From 634cdddf129dae1ab36dbd007ebceb995b0dce3f Mon Sep 17 00:00:00 2001 From: yp9522 Date: Mon, 14 Jul 2025 17:26:42 +0800 Subject: [PATCH] FixAsyncOverloadMethod Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICM76S Signed-off-by: yp9522 --- ets2panda/checker/ETSAnalyzer.cpp | 6 +++ .../ast/compiler/ets/AsyncOverloadMethod.ets | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 ets2panda/test/ast/compiler/ets/AsyncOverloadMethod.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 7d86fab062e..ef6fc65d53a 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -261,6 +261,12 @@ checker::Type *ETSAnalyzer::Check(ir::MethodDefinition *node) const return node->TsType(); } + if (scriptFunc->IsOverload() && node->BaseOverloadMethod() != nullptr && node->IsAsync() && + !node->BaseOverloadMethod()->IsAsync()) { + checker->LogError(diagnostic::OVERLOAD_SAME_ACCESS_MODIFIERS_STATIC_ASYNC, {}, node->Start()); + return returnErrorType(); + } + return CheckMethodDefinitionHelper(checker, node); } diff --git a/ets2panda/test/ast/compiler/ets/AsyncOverloadMethod.ets b/ets2panda/test/ast/compiler/ets/AsyncOverloadMethod.ets new file mode 100755 index 00000000000..5503d91d9be --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/AsyncOverloadMethod.ets @@ -0,0 +1,38 @@ +/* + * 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 Test { + regularFunc(): boolean { + return true; + } + + async regularFunc(param: () => boolean): Promise { + return param(); + } + + callOverloadRegularFunc(): void { + let is_call_regular_func1 = await this.regularFunc((): boolean => { return true }); + arktest.assertEQ(is_call_regular_func1, true) + + let is_call_regular_func2 = await this.regularFunc((): boolean => { return false }); + arktest.assertEQ(is_call_regular_func2, false) + } +} + +function main(): void { + new Test().callOverloadRegularFunc(); +} + +/* @@? 21:5 Error TypeError: Overload alias and overloaded method name must have exactly the same modifiers (static, async). */ -- Gitee