From b7d55d9af984419e66477cfda823fefece392bf4 Mon Sep 17 00:00:00 2001 From: zengzengran Date: Tue, 29 Jul 2025 10:28:28 +0800 Subject: [PATCH] Fix super overload alias call error interception Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICOKCT Description: super.overload alias is incorrectly intercepted by ValidateNamespaceProperty(). Tested-by: ninja tests (passed) ets_testrunner (passed) Signed-off-by: zengzengran # --- ets2panda/checker/ets/object.cpp | 14 +++---- .../runtime/ets/first_match/super_call.ets | 41 +++++++++++++++++++ .../runtime/ets/first_match/this_call.ets | 39 ++++++++++++++++++ 3 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 ets2panda/test/runtime/ets/first_match/super_call.ets create mode 100644 ets2panda/test/runtime/ets/first_match/this_call.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index e42f1d760e..6bd7718a43 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1893,15 +1893,15 @@ void ETSChecker::ValidateNamespaceProperty(varbinder::Variable *property, const { ir::AstNode *parent = nullptr; if (property->TsType() != nullptr && !property->TsType()->IsTypeError()) { - if (property->TsType()->IsETSMethodType() && !property->HasFlag(varbinder::VariableFlags::OVERLOAD)) { + if (property->TsType()->IsETSMethodType()) { auto funcType = property->TsType()->AsETSFunctionType(); - property = funcType->CallSignatures()[0]->OwnerVar(); + property = !property->HasFlag(varbinder::VariableFlags::OVERLOAD) + ? funcType->CallSignatures()[0]->OwnerVar() + : property; ES2PANDA_ASSERT(property != nullptr); - } else { - if (ident->Parent()->IsMemberExpression() && - ident->Parent()->AsMemberExpression()->Object()->IsSuperExpression()) { - LogError(diagnostic::SUPER_NOT_ACCESSIBLE, {ident->Name()}, ident->Start()); - } + } else if (ident->Parent()->IsMemberExpression() && + ident->Parent()->AsMemberExpression()->Object()->IsSuperExpression()) { + LogError(diagnostic::SUPER_NOT_ACCESSIBLE, {ident->Name()}, ident->Start()); } } diff --git a/ets2panda/test/runtime/ets/first_match/super_call.ets b/ets2panda/test/runtime/ets/first_match/super_call.ets new file mode 100644 index 0000000000..78c093873d --- /dev/null +++ b/ets2panda/test/runtime/ets/first_match/super_call.ets @@ -0,0 +1,41 @@ +/* + * 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. + */ + +class MyArray { + public pushArray(...val: T[]): string { + return "invoke1"; + } + + public pushOne(val: T): string { + return "invoke2"; + } + overload push{ pushOne, pushArray } +} + +class MySubArray extends MyArray { + override pushArray(...val: T[]): string { + return super.push(...val); + } + + override pushOne(val: T): string { + return super.push(val); + } +} + +function main() { + let test = new MySubArray(); + arktest.assertEQ(test.push(1), "invoke2") + arktest.assertEQ(test.push(1, 2, 3), "invoke1") +} diff --git a/ets2panda/test/runtime/ets/first_match/this_call.ets b/ets2panda/test/runtime/ets/first_match/this_call.ets new file mode 100644 index 0000000000..7c3fb505cb --- /dev/null +++ b/ets2panda/test/runtime/ets/first_match/this_call.ets @@ -0,0 +1,39 @@ +/* + * 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. + */ + +class MyArray { + public pushArray(...val: T[]): string { + return "invoke1"; + } + + public pushOne(val: T): string { + return "invoke2"; + } + overload push{ pushOne, pushArray } + + public testThisCall1(val: T){ + return this.push(val); + } + + public testThisCall2(...val: T[]){ + return this.push(...val); + } +} + +function main() { + let test = new MyArray(); + arktest.assertEQ(test.testThisCall1(1), "invoke2"); + arktest.assertEQ(test.testThisCall2(1, 2, 3), "invoke1"); +} -- Gitee