diff --git a/ets2panda/checker/ets/assignAnalyzer.cpp b/ets2panda/checker/ets/assignAnalyzer.cpp index a411f9d429bf07f01adc90396a3a08a1261112b7..5a80f4b41ddb94c64d77f1c5d2b18c4189813219 100644 --- a/ets2panda/checker/ets/assignAnalyzer.cpp +++ b/ets2panda/checker/ets/assignAnalyzer.cpp @@ -1184,8 +1184,26 @@ void AssignAnalyzer::AnalyzeUpdateExpr(const ir::UpdateExpression *updateExpr) void AssignAnalyzer::AnalyzeArrowFunctionExpr(const ir::ArrowFunctionExpression *arrowFuncExpr) { - // NOTE (pantos) handle lamdas correctly - (void)arrowFuncExpr; + auto *func = arrowFuncExpr->Function(); + ES2PANDA_ASSERT(func != nullptr); + if (func->Body() == nullptr || func->IsProxy()) { + return; + } + + Set initsPrev = inits_; + Set uninitsPrev = uninits_; + ScopeGuard save(firstAdr_, nextAdr_, returnAdr_, isInitialConstructor_); + hasTryFinallyBlock_ = func->IsAnyChild([](ir::AstNode *ast) { + return (ast->Type() == ir::AstNodeType::TRY_STATEMENT && ast->AsTryStatement()->FinallyBlock() != nullptr); + }); + isInitialConstructor_ = false; + firstAdr_ = nextAdr_; + + AnalyzeStat(func->Body()); + CheckPendingExits(); + + inits_ = std::move(initsPrev); + uninits_ = std::move(uninitsPrev); } util::StringView AssignAnalyzer::GetVariableType(const ir::AstNode *node) const diff --git a/ets2panda/test/ast/compiler/ets/assign_analyzer_for_lambda_neg.ets b/ets2panda/test/ast/compiler/ets/assign_analyzer_for_lambda_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..3e9c2de64cd03a7fb8063db00f2a2d0d5b1ca280 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/assign_analyzer_for_lambda_neg.ets @@ -0,0 +1,32 @@ +/* + * 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 it(s:string, cb: (done: ()=> void) => Promise) {} +function foo(s: SymKey) {} +interface SymKey { + index: number; + name: string; +} + +it("test", async (done: () => void): Promise => { + try { + let algName: string = "SHA256"; + let key: SymKey; + foo(/* @@ label */key) + } catch (error) {} + done(); +}); + +/* @@@ label Error TypeError: Variable 'key' is used before being assigned. */