diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index d3a90c4205235a2155fc89f93ea06f06de989746..933486de2ba356f4a9e17397c10942bc2b8ee1a7 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -268,6 +268,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 0000000000000000000000000000000000000000..5503d91d9be11bd052c6e9d99001b903916462a6 --- /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). */