From 48f72be6785df934b924b61f248ad275ff6582df Mon Sep 17 00:00:00 2001 From: zhaoshuting Date: Fri, 15 Aug 2025 15:44:16 +0800 Subject: [PATCH] Cherry-pick !8183 and !7911 to 0728 Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICWPGB Signed-off-by: zhaoshuting --- ets2panda/checker/ETSAnalyzer.cpp | 20 +++++++++++-- ets2panda/checker/ets/object.cpp | 4 +++ .../ets/interface_class_implement_extend.ets | 27 +++++++++++++++++ .../ets/async_lambda_return_type_test.ets | 30 +++++++++++++++++++ .../declgen-ets2ts-runtime-ignored.txt | 1 + 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/interface_class_implement_extend.ets create mode 100644 ets2panda/test/runtime/ets/async_lambda_return_type_test.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 80da256ea0..ee0114c5d2 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1116,6 +1116,21 @@ void TryInferPreferredType(ir::ArrowFunctionExpression *expr, checker::Type *pre } } +static bool IsUnionTypeContainingPromise(checker::Type *type, ETSChecker *checker) +{ + if (!type->IsETSUnionType()) { + return false; + } + for (auto subtype : type->AsETSUnionType()->ConstituentTypes()) { + if (subtype->IsETSObjectType() && + subtype->AsETSObjectType()->GetOriginalBaseType() == checker->GlobalBuiltinPromiseType()) { + return true; + } + } + + return false; +} + checker::Type *ETSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const { ETSChecker *checker = GetETSChecker(); @@ -1177,8 +1192,9 @@ checker::Type *ETSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const if (expr->Function()->ReturnTypeAnnotation() == nullptr) { if (expr->Function()->IsAsyncFunc()) { auto *retType = signature->ReturnType(); - if (!retType->IsETSObjectType() || - retType->AsETSObjectType()->GetOriginalBaseType() != checker->GlobalBuiltinPromiseType()) { + if (!IsUnionTypeContainingPromise(retType, checker) && + (!retType->IsETSObjectType() || + retType->AsETSObjectType()->GetOriginalBaseType() != checker->GlobalBuiltinPromiseType())) { auto returnType = checker->CreateETSAsyncFuncReturnTypeFromBaseType(signature->ReturnType()); ES2PANDA_ASSERT(returnType != nullptr); expr->Function()->Signature()->SetReturnType(returnType->PromiseType()); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index f0869bbb56..c9f8409933 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1120,6 +1120,10 @@ void ETSChecker::ValidateNonOverriddenFunction(ETSObjectType *classType, ArenaVe auto superClassType = classType->SuperType(); while (!functionOverridden && superClassType != nullptr) { for (auto *field : superClassType->Fields()) { + if (field->Declaration()->Node()->AsClassProperty()->IsStatic()) { + continue; + } + if (field->Name() == (*it)->Name()) { auto *newProp = field->Declaration() ->Node() diff --git a/ets2panda/test/ast/compiler/ets/interface_class_implement_extend.ets b/ets2panda/test/ast/compiler/ets/interface_class_implement_extend.ets new file mode 100644 index 0000000000..afa9486646 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/interface_class_implement_extend.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023-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 AA { + X :int; +} +class A implements AA{ + static X :int=1; +} +class extendA extends A{ + +} + +/* @@? 19:22 Error TypeError: A is not abstract and does not implement getter for X property in AA */ +/* @@? 22:24 Error TypeError: extendA is not abstract and does not implement getter for X property in AA */ diff --git a/ets2panda/test/runtime/ets/async_lambda_return_type_test.ets b/ets2panda/test/runtime/ets/async_lambda_return_type_test.ets new file mode 100644 index 0000000000..71a3cec3a5 --- /dev/null +++ b/ets2panda/test/runtime/ets/async_lambda_return_type_test.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ + +let money_box: number[] = Array.from([10.0, 5.0, 20.0, 50.0, 100.0, 200.0, 500.0]) +let lock: AsyncLock = AsyncLock.request("lock_1") +let len: number = 0 + +async function initialize() { + len = await lock.lockAsync(async () => { + return money_box.length + }) +} + +function main() { + initialize().then(() => { + arktest.assertEQ(len, 7) + }) +} diff --git a/ets2panda/test/test-lists/declgenets2ts/ets-runtime/declgen-ets2ts-runtime-ignored.txt b/ets2panda/test/test-lists/declgenets2ts/ets-runtime/declgen-ets2ts-runtime-ignored.txt index 91e2b0af73..4444cd873b 100644 --- a/ets2panda/test/test-lists/declgenets2ts/ets-runtime/declgen-ets2ts-runtime-ignored.txt +++ b/ets2panda/test/test-lists/declgenets2ts/ets-runtime/declgen-ets2ts-runtime-ignored.txt @@ -29,3 +29,4 @@ fuzz/too_many_async.ets typeAlias_2.ets Multiline_string.ets Multiline_string_escape_char.ets +async_lambda_return_type_test.ets -- Gitee