From 929411187b285e1d666a535f23159dc6f78d3ab3 Mon Sep 17 00:00:00 2001 From: duyuhan Date: Tue, 26 Aug 2025 14:26:25 +0800 Subject: [PATCH] Fix TypeError while building Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICUNGE Signed-off-by: duyuhan --- ets2panda/checker/ETSAnalyzer.cpp | 9 ++++ .../ets/typeof_overloaded_functions.ets | 41 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/typeof_overloaded_functions.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index a35397d0b8..caa1795d59 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1896,6 +1896,15 @@ static Type *TransformTypeForMethodReference(ETSChecker *checker, ir::Expression } if (signatures.size() > 1U) { + ir::Expression *rootExpr = expr; + while (rootExpr->Parent()->IsExpression()) { + rootExpr = rootExpr->Parent()->AsExpression(); + if (rootExpr->IsTypeofExpression()) { + auto *signature = signatures.at(0); + auto *arrowType = checker->CreateETSArrowType(signature); + return arrowType; + } + } checker->LogError(diagnostic::OVERLOADED_METHOD_AS_VALUE, getUseSite()); return checker->GlobalTypeError(); } diff --git a/ets2panda/test/ast/compiler/ets/typeof_overloaded_functions.ets b/ets2panda/test/ast/compiler/ets/typeof_overloaded_functions.ets new file mode 100644 index 0000000000..b3cf27d084 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/typeof_overloaded_functions.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. + */ + +interface InterfaceA{ + methodA():string; +} + +class ClassA{ + methodA():string{ + return 'methodA'; + } +} + +class ClassB extends ClassA implements InterfaceA{ + methodB():string{ + return 'methodB'; + } + methodB(x:string):string{ + return x; + } +} + +function main(){ + let a=new ClassB(); + arktest.assertEQ(a.methodA(),'methodA'); + arktest.assertEQ(a.methodB(),'methodB'); + arktest.assertEQ(typeof a.methodA,'function'); + arktest.assertEQ(typeof a.methodB,'function'); +} \ No newline at end of file -- Gitee