From 7bb237696432f06436880b11d03710f3f8a433c6 Mon Sep 17 00:00:00 2001 From: xingshunxiang Date: Tue, 26 Aug 2025 15:43:45 +0800 Subject: [PATCH] Missing CTE in Assignment Analyzer of Lambda Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICUUQY?from=project-issue Description: Missing CTE in Assignment Analyzer of Lambda Reason: Missing CTE in Assignment Analyzer of Lambda, because the Assignment Analyzer of lambda haven't been implemented yet Tests: ninja tests passed tests/tests-u-runner/runner.sh --ets-cts --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-func-tests --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --astchecker --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-runtime --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --parser --no-js --show-progress --build-dir x64.release --processes=all passed Signed-off-by: xingshunxiang --- ets2panda/checker/ets/assignAnalyzer.cpp | 22 +++++++++++-- .../ets/assign_analyzer_for_lambda_neg.ets | 32 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/assign_analyzer_for_lambda_neg.ets diff --git a/ets2panda/checker/ets/assignAnalyzer.cpp b/ets2panda/checker/ets/assignAnalyzer.cpp index a411f9d429..5a80f4b41d 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 0000000000..3e9c2de64c --- /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. */ -- Gitee