diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index d3416d9181cbaed8d569e1a97c825d42ccde8e6b..a10d2db57f83951339b625280618e2e4ba27e70d 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 9a30d7bb961d069a6375c232c325bc4db228d4dd..72d28a3614a474f7bdfefdf7c38231074a5387c5 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 6c3e10213229a8f567786349917c34ed17a97b67..ee9fd7f3da67951f1f8795e15728c725fe76a1e3 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 61b7dbe457b87419106d7fb7908b6bc14eedb5ad..6cb06f2cb9eb27800444766f4879f5fdf2cefc93 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 0000000000000000000000000000000000000000..908e8c1d2c852feb30999b87f8b0961909680318 --- /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