From 94af655e2ea7f52f0383bfefb5a1b7c6401254fd Mon Sep 17 00:00:00 2001 From: yp9522 Date: Mon, 28 Jul 2025 08:15:21 +0000 Subject: [PATCH] Fix lambda without type bug Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICGQGZ Signed-off-by: yp9522 --- ets2panda/checker/ets/function.cpp | 10 ++++++++++ .../lambda_in_record_without_return_type.ets | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 ets2panda/test/runtime/ets/lambda_in_record_without_return_type.ets diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 44b4e29a22..1aaf82610d 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -482,6 +482,16 @@ bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, if (CheckLambdaAssignable(targetParm->AsETSParameterExpression(), lambda)) { continue; } + if (argument->TsType() != nullptr && + checker::InvocationContext( + Relation(), argument, argument->TsType(), substitutedSig->Params()[index]->TsType(), + argument->Start(), + {{diagnostic::TYPE_MISMATCH_AT_IDX, + {argument->TsType(), substitutedSig->Params()[index]->TsType(), index + 1}}}, + flags | TypeRelationFlag::ONLY_CHECK_WIDENING | TypeRelationFlag::NO_THROW) + .IsInvocable()) { + continue; + } return false; } diff --git a/ets2panda/test/runtime/ets/lambda_in_record_without_return_type.ets b/ets2panda/test/runtime/ets/lambda_in_record_without_return_type.ets new file mode 100644 index 0000000000..f026ad4d1c --- /dev/null +++ b/ets2panda/test/runtime/ets/lambda_in_record_without_return_type.ets @@ -0,0 +1,17 @@ +/* + * 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 A {} +let a : Recordvoid)> = {"1":new A(), 2:()=>{return;}} \ No newline at end of file -- Gitee