From 011ca37d9c788e12c4a362fe40839f16d8cab4a2 Mon Sep 17 00:00:00 2001 From: Utku Enes GURSEL Date: Mon, 23 Jun 2025 16:59:27 +0300 Subject: [PATCH] tsType double check before arithmetic Issue: ICGXQT Description: Recheck binary expression parts before unboxing. Signed-off-by: Utku Enes GURSEL --- .../compiler/lowering/ets/lambdaLowering.cpp | 8 ++++++++ .../LambdaLoweringWithReferencedVariable.ets | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/LambdaLoweringWithReferencedVariable.ets diff --git a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp index 5e4836e445..5ff3beda1e 100644 --- a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp +++ b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp @@ -215,6 +215,13 @@ ParamsAndVarMap CreateLambdaCalleeParameters(public_lib::Context *ctx, ir::Arrow return {resParams, varMap}; } +void AddTsTypeToIdentifier(varbinder::Variable *ref, ir::Identifier *id) +{ + if (id->IsTyped() && id->AsTyped()->TsType() == nullptr && ref->TsType() != nullptr) { + id->AsTyped()->SetTsType(ref->TsType()); + } +} + static void ProcessCalleeMethodBody(ir::AstNode *body, checker::ETSChecker *checker, varbinder::Scope *paramScope, checker::Substitution *substitution, ArenaMap const &varMap) @@ -228,6 +235,7 @@ static void ProcessCalleeMethodBody(ir::AstNode *body, checker::ETSChecker *chec auto *id = node->AsIdentifier(); if (auto ref = varMap.find(id->Variable()); ref != varMap.end()) { id->SetVariable(ref->second); + AddTsTypeToIdentifier(ref->second, id); } } if (substitution == nullptr) { diff --git a/ets2panda/test/ast/compiler/ets/LambdaLoweringWithReferencedVariable.ets b/ets2panda/test/ast/compiler/ets/LambdaLoweringWithReferencedVariable.ets new file mode 100644 index 0000000000..0da0d06007 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/LambdaLoweringWithReferencedVariable.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. + */ + + let FooArray = ["a", "b", "c"]; + + let FooArrayMapped = FooArray.map(x => x + " is mapped"); + + let FooArrayMappedAndChecked = FooArray.map(x => x == "a"); -- Gitee