From 5b7c194bebec655cb9a7336b8f0b8fee00de8db6 Mon Sep 17 00:00:00 2001 From: tsatsulya Date: Thu, 3 Jul 2025 16:53:29 +0300 Subject: [PATCH] fix constant arrow function folding Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICR1XC Signed-off-by: tsatsulya --- .../lowering/ets/constantExpressionLowering.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 0d304337ed..5872b9c841 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -1236,7 +1236,15 @@ static bool IsConstantExpression(ir::AstNode *expr) if (expr->IsIdentifier()) { auto var = ResolveIdentifier(expr->AsIdentifier()); - return var != nullptr && var->Declaration()->IsConstDecl(); + if (var == nullptr || !var->Declaration()->IsConstDecl()) { + return false; + } + // ermolaevavarvara: Identifier is not constant if the variable is ArrowFunction (f.e. const foo = (n: number) + // => {} is not constant expr) + if (var->Declaration()->Node()->IsClassProperty()) { + return !var->Declaration()->Node()->AsClassProperty()->Value()->IsArrowFunctionExpression(); + } + return true; } if (expr->IsMemberExpression()) { -- Gitee