From 24346883db27c797b91db72d945f3ff92db919f8 Mon Sep 17 00:00:00 2001 From: fcc Date: Thu, 17 Jul 2025 16:40:32 +0800 Subject: [PATCH] fix crash when overload declaration is recursive Ignore the method name when it is the same with overload declaration. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMZZT Signed-off-by: fcc --- ets2panda/checker/types/ets/etsObjectType.cpp | 3 +++ .../ets/overload/recursive_overload.ets | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/overload/recursive_overload.ets diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 177a0c679a..9ed06eb019 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -312,6 +312,9 @@ void ETSObjectType::AddSignatureFromOverload(std::vector &signature methodSignature.clear(); util::StringView methodName = method->IsIdentifier() ? method->AsIdentifier()->Name() : method->AsTSQualifiedName()->Right()->Name(); + if (methodName == overloadDeclaration->Id()->Name()) { + continue; + } CollectSignaturesForSyntheticType(methodSignature, methodName, flags, overloadDeclarationCall); if (!methodSignature.empty()) { signatures.emplace_back(methodSignature.front()); diff --git a/ets2panda/test/ast/compiler/ets/overload/recursive_overload.ets b/ets2panda/test/ast/compiler/ets/overload/recursive_overload.ets new file mode 100644 index 0000000000..fa2dae05b4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/overload/recursive_overload.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +overload foo{ + foo +} + +/* @@? 17:3 TypeError: overloaded name must refer to an accessible method. */ -- Gitee