diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index d6db10920758cd918746602136706ca2a7083632..c51f8fad4db578b4d1e7fd8bc12ef2d2424c9bce 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2584,14 +2584,14 @@ bool ETSChecker::CheckLambdaAssignableUnion(ir::AstNode *typeAnn, ir::ScriptFunc bool assignable = false; for (auto *type : typeAnn->AsETSUnionType()->Types()) { if (type->IsETSFunctionType()) { - assignable |= lambda->Params().size() == type->AsETSFunctionType()->Params().size(); + assignable |= lambda->Params().size() <= type->AsETSFunctionType()->Params().size(); continue; } if (type->IsETSTypeReference()) { auto aliasType = util::Helpers::DerefETSTypeReference(type); assignable |= aliasType->IsETSFunctionType() && - lambda->Params().size() == aliasType->AsETSFunctionType()->Params().size(); + lambda->Params().size() <= aliasType->AsETSFunctionType()->Params().size(); } } diff --git a/ets2panda/test/runtime/ets/lambdaParamsInfer4.ets b/ets2panda/test/runtime/ets/lambdaParamsInfer4.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e12277b3592c0ff1279c348fa793d18e4abb177 --- /dev/null +++ b/ets2panda/test/runtime/ets/lambdaParamsInfer4.ets @@ -0,0 +1,19 @@ +/* + * 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(fun: ((a: number) => Int) | undefined) { + return 1; +} +arktest.assertEQ(foo((() => { return 1 })), 1); diff --git a/ets2panda/test/runtime/ets/lambdaParamsInfer5.ets b/ets2panda/test/runtime/ets/lambdaParamsInfer5.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5dc3e873a8c2facf088d095cad7c95527048b06 --- /dev/null +++ b/ets2panda/test/runtime/ets/lambdaParamsInfer5.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +type callback = (a: number) => Int; +function foo(fun: callback | undefined) { + return 1; +} +arktest.assertEQ(foo((() => { return 1 })), 1);