diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 7034998575815c6518c0c4014ccf070c8b323e2e..3d07991be55c49627d27a3e4ab7840b40d9b3619 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -230,6 +230,7 @@ static void RemoveInvalidTypeMarkers(ir::AstNode *node) noexcept static void ResetInferredTypeInArrowBody(ir::AstNode *body, ETSChecker *checker, std::unordered_set &inferredVarSet) { + checker::ScopeContext scopeCtx(checker, body->Parent()->Scope()); std::function doNode = [&](ir::AstNode *node) { if (node->IsIdentifier()) { auto *id = node->AsIdentifier(); @@ -237,10 +238,11 @@ static void ResetInferredTypeInArrowBody(ir::AstNode *body, ETSChecker *checker, return; } - id->Check(checker); - if (auto *parent = id->Parent(); parent->IsMemberExpression()) { - parent->AsMemberExpression()->Check(checker); + ir::AstNode *checkNode = id; + while (checkNode->Parent()->IsMemberExpression() || checkNode->Parent()->IsCallExpression()) { + checkNode = checkNode->Parent(); } + checkNode->Check(checker); } if (node->IsVariableDeclarator()) { auto *id = node->AsVariableDeclarator()->Id(); diff --git a/ets2panda/test/runtime/ets/lambda_type_infer_1.ets b/ets2panda/test/runtime/ets/lambda_type_infer_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..be39b86df6c2c9da3a13e63c0dc34776558f801d --- /dev/null +++ b/ets2panda/test/runtime/ets/lambda_type_infer_1.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +interface A { +} + +interface test { + t: A[] +} + +interface B { + unsorted: A[]; +} + +class C { + static foo(...arg: B[]): void { }; +} + +const tests: test[] = []; + +C.foo(...tests.map((test): B => ({ + unsorted: [...test.t.map((m): A => ({}))], +})));