From f487188b81ad30bdda82aedaa588ee00797c0a17 Mon Sep 17 00:00:00 2001 From: Anna Antipina Date: Tue, 12 Dec 2023 12:13:45 +0300 Subject: [PATCH] Title: Remove the mandatory of override modifier for class inheriting Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8NRHE Description: Remove the mandatory of override modifier for class inheriting because The spec in 9.6.5 Override Methods says: The use of override is optional. Test: ${ARK_SOURCE_DIR}/tests/tests-u-runner/runner.sh ${ARK_SOURCE_DIR} --ets-run time --build-dir="${ARK_BUILD_DIR}" --heap-verifier="fail_on_verification:pre:into:b efore_g1_concurrent:post" --timeout=30 --force-generate --test-file Override-2.ets Signed-off-by: Anna Antipina --- ets2panda/checker/ets/function.cpp | 4 +-- ets2panda/ir/astNode.h | 5 +++ ...methodOverrideWithoutModifier-expected.txt | 1 - .../ets/static_function_hide_3-expected.txt | 2 +- ets2panda/test/runtime/ets/Override-2.ets | 32 +++++++++++++++++++ 5 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 ets2panda/test/runtime/ets/Override-2.ets diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index d3416d9181..a10d2db57f 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -911,9 +911,7 @@ bool ETSChecker::IsMethodOverridesOther(Signature *target, Signature *source) return false; } - if (!source->Function()->IsOverride()) { - ThrowTypeError("Method overriding requires 'override' modifier", source->Function()->Start()); - } + source->Function()->SetOverride(); return true; } } diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 9a30d7bb96..72d28a3614 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -305,6 +305,11 @@ public: return (flags_ & ModifierFlags::OVERRIDE) != 0; } + void SetOverride() noexcept + { + flags_ |= ModifierFlags::OVERRIDE; + } + [[nodiscard]] bool IsAsync() const noexcept { return (flags_ & ModifierFlags::ASYNC) != 0; diff --git a/ets2panda/test/compiler/ets/methodOverrideWithoutModifier-expected.txt b/ets2panda/test/compiler/ets/methodOverrideWithoutModifier-expected.txt index 6c3e102132..ee9fd7f3da 100644 --- a/ets2panda/test/compiler/ets/methodOverrideWithoutModifier-expected.txt +++ b/ets2panda/test/compiler/ets/methodOverrideWithoutModifier-expected.txt @@ -735,4 +735,3 @@ } } } -TypeError: Method overriding requires 'override' modifier [methodOverrideWithoutModifier.ets:23:15] diff --git a/ets2panda/test/parser/ets/static_function_hide_3-expected.txt b/ets2panda/test/parser/ets/static_function_hide_3-expected.txt index 61b7dbe457..6cb06f2cb9 100644 --- a/ets2panda/test/parser/ets/static_function_hide_3-expected.txt +++ b/ets2panda/test/parser/ets/static_function_hide_3-expected.txt @@ -735,4 +735,4 @@ } } } -TypeError: Method overriding requires 'override' modifier [static_function_hide_3.ets:21:8] +TypeError: bar(): void in BClass cannot override bar(): void in AClass because overridden method is static. [static_function_hide_3.ets:21:8] diff --git a/ets2panda/test/runtime/ets/Override-2.ets b/ets2panda/test/runtime/ets/Override-2.ets new file mode 100644 index 0000000000..908e8c1d2c --- /dev/null +++ b/ets2panda/test/runtime/ets/Override-2.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A { + met(): string { + return "a" + } +} + +class B extends A { + met(): string { + return "b" + } +} + + +function main() { + let a: A = new B() + assert a.met() == "b" +} \ No newline at end of file -- Gitee