From 3dc8d22a24e8c1ed45fc6ce83ae380b276ad2342 Mon Sep 17 00:00:00 2001 From: daizihan Date: Sat, 16 Aug 2025 20:12:45 +0800 Subject: [PATCH] Fix override bug Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICTB4N?from=project-issue Signed-off-by: daizihan --- ets2panda/checker/ets/object.cpp | 2 +- ets2panda/test/runtime/ets/this_override.ets | 35 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/runtime/ets/this_override.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index d371eac06c..0b256ecdfc 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -957,7 +957,7 @@ void ETSChecker::GetInterfacesOfClass(ETSObjectType *type, ArenaVectorFunction()->IsStatic() == sig->Function()->IsStatic()) { + if (AreOverrideCompatible(sigFunc, sig) && sigFunc->Function()->IsStatic() == sig->Function()->IsStatic()) { SavedTypeRelationFlagsContext const savedFlags(Relation(), Relation()->GetTypeRelationFlags() | TypeRelationFlag::IGNORE_TYPE_PARAMETERS); if (CheckIfInterfaceCanBeFoundOnDifferentPaths(classType, sigFunc->Owner(), this) && diff --git a/ets2panda/test/runtime/ets/this_override.ets b/ets2panda/test/runtime/ets/this_override.ets new file mode 100644 index 0000000000..5e40be9ddb --- /dev/null +++ b/ets2panda/test/runtime/ets/this_override.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + + +interface SCM { + foo(a: string): this { return this } +} + +class SC implements SCM { +} + +interface GA extends SCM { + foo(a: string) : this { return this } +} + +class GM extends SC implements GA { + foo(a: string) : this { return this } +} + +function main() { + let a = new GM(); + arktest.assertTrue(a.foo("test") instanceof GM); +} -- Gitee