diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 1c1b999761d401bf84758bf6c09817102149345b..2c5b418b0b4a78819c8d4c1e94a13209ba5d49c3 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -958,6 +958,15 @@ static Type *GetAppropriatePreferredType(Type *originalType, std::functionIsETSAsyncFuncReturnType() && + originalType->AsETSAsyncFuncReturnType()->GetPromiseTypeArg()->IsETSObjectType() && + predicate( + originalType->AsETSAsyncFuncReturnType()->GetPromiseTypeArg()->AsETSObjectType()->GetOriginalBaseType())) { + return GetAppropriatePreferredType( + originalType->AsETSAsyncFuncReturnType()->GetPromiseTypeArg()->AsETSObjectType()->GetOriginalBaseType(), + predicate); + } + if (!originalType->IsETSUnionType()) { return nullptr; } diff --git a/ets2panda/test/ast/compiler/ets/async_return_type.ets b/ets2panda/test/ast/compiler/ets/async_return_type.ets new file mode 100644 index 0000000000000000000000000000000000000000..c49f738a408ce8542578a81dd90afd42028308c0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/async_return_type.ets @@ -0,0 +1,45 @@ +/* + * 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. + */ + +async function test(): Promise { + const n1: number = 1; + return n1; +}; + +const testLambda = async (): Promise => { + const n1: number = 2; + return n1; +}; + +async function test1(): Promise { + const n1: double = 1; + return n1; +}; + +const testLambda1 = async (): Promise => { + const n1: double = 2; + return n1; +}; + +async function test2(): Promise { + const n1: double = 1; + return n1; +}; + +const testLambda2 = async (): Promise => { + const n1: double = 2; + return n1; +}; +