diff --git a/ets2panda/ast_verifier/invariants/everyChildHasValidParent.cpp b/ets2panda/ast_verifier/invariants/everyChildHasValidParent.cpp index 7761dc5a5e0f5a427bff91e95fcbe23bf8b46089..468ba99a4ca3665e723dda4ea9e3bcbba7ebc96f 100644 --- a/ets2panda/ast_verifier/invariants/everyChildHasValidParent.cpp +++ b/ets2panda/ast_verifier/invariants/everyChildHasValidParent.cpp @@ -32,7 +32,7 @@ CheckResult EveryChildHasValidParent::operator()(const ir::AstNode *ast) auto overloads = maybeBaseOverloadMethod->Overloads(); auto res = std::find_if(overloads.begin(), overloads.end(), [node](ir::MethodDefinition *m) { return m == node; }); - return res != overloads.end(); + return res != overloads.end() || maybeBaseOverloadMethod->AsyncPairMethod() == node; } return false; }; diff --git a/ets2panda/compiler/lowering/ets/asyncMethodLowering.cpp b/ets2panda/compiler/lowering/ets/asyncMethodLowering.cpp index 01d054a71719af0a6a204e77f7e8f90baa2264f2..d93cfa4310fe86dde70c7d116a4ff31f60281fc5 100644 --- a/ets2panda/compiler/lowering/ets/asyncMethodLowering.cpp +++ b/ets2panda/compiler/lowering/ets/asyncMethodLowering.cpp @@ -173,11 +173,16 @@ void ComposeAsyncImplMethod(checker::ETSChecker *checker, ir::MethodDefinition * node->SetAsyncPairMethod(implMethod); ES2PANDA_ASSERT(node->Function() != nullptr); - if (node->Function()->IsOverload()) { + if (node->Function()->IsOverload() && node->BaseOverloadMethod()->AsyncPairMethod() != nullptr) { auto *baseOverloadImplMethod = node->BaseOverloadMethod()->AsyncPairMethod(); ES2PANDA_ASSERT(implMethod->Function() != nullptr && baseOverloadImplMethod->Function() != nullptr); implMethod->Function()->Id()->SetVariable(baseOverloadImplMethod->Function()->Id()->Variable()); baseOverloadImplMethod->AddOverload(implMethod); + } else if (node->Function()->IsOverload() && node->BaseOverloadMethod()->AsyncPairMethod() == nullptr) { + // If it's base overload function doesnot marked as async, + // then current AsyncImpl should be treated as AsyncPairMethod in base overload. + node->BaseOverloadMethod()->SetAsyncPairMethod(implMethod); + classDef->Body().push_back(implMethod); } else { classDef->Body().push_back(implMethod); } diff --git a/ets2panda/test/runtime/ets/async_overload.ets b/ets2panda/test/runtime/ets/async_overload.ets new file mode 100644 index 0000000000000000000000000000000000000000..f50ea6320030f987bf2ba8843acf6a1f174389c1 --- /dev/null +++ b/ets2panda/test/runtime/ets/async_overload.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +function foo(a : string){ + return 1; +} + +async function foo() { + return 2 +} + +async function foo(a: int) { + return 3 +} + +function main() { + arktest.assertEQ(foo("test"), 1); + arktest.assertEQ(await foo(), 2); + arktest.assertEQ(await foo(1), 3); +}