From f34446918da9a022a17acc7754d1ae927ff98104 Mon Sep 17 00:00:00 2001 From: Csaba Osztrogonac Date: Wed, 6 Aug 2025 19:10:58 +0200 Subject: [PATCH] [ArkTS FE] Fix Function object name in lambdas Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICROCA Internal issue: #27329 Reason: Incomplete implementation Description: spec 3.19.1 Type Function If a lambda is assigned to a variable of Function type, then the associated name is that of the variable We need to enable function name if lambda is assigned to a variable too. Test: ninja tests passed, CTS tests passed, new runtime test added Change-Id: Ic8dc929e067a5cfa5c5cc8bc5477d1b2d2c8af46 Signed-off-by: Csaba Osztrogonac --- .../compiler/lowering/ets/lambdaLowering.cpp | 3 ++ ets2panda/test/runtime/ets/function_name.ets | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 ets2panda/test/runtime/ets/function_name.ets diff --git a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp index b215a47e80..30fa057f9c 100644 --- a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp +++ b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp @@ -1255,6 +1255,9 @@ static ir::AstNode *ConvertLambda(public_lib::Context *ctx, ir::ArrowFunctionExp info.originalFuncName = lambda->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Name(); } else if ((lambda->Parent() != nullptr) && lambda->Parent()->IsClassProperty()) { info.originalFuncName = lambda->Parent()->AsClassProperty()->Id()->Name(); + } else if ((lambda->Parent() != nullptr) && lambda->Parent()->IsAssignmentExpression() && + lambda->Parent()->AsAssignmentExpression()->Left()->IsIdentifier()) { + info.originalFuncName = lambda->Parent()->AsAssignmentExpression()->Left()->AsIdentifier()->Name(); } auto capturedVars = FindCaptured(allocator, lambda); diff --git a/ets2panda/test/runtime/ets/function_name.ets b/ets2panda/test/runtime/ets/function_name.ets new file mode 100644 index 0000000000..97ecfc8882 --- /dev/null +++ b/ets2panda/test/runtime/ets/function_name.ets @@ -0,0 +1,37 @@ +/* + * 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 global_f1: Function = (): void => {} +let global_f2: Function; +global_f2 = global_f1; +let global_f3: Function; +global_f3 = (): void => {} + +function main(): void { + arktest.assertEQ(global_f1.name, "global_f1") + arktest.assertEQ(global_f2.name, "global_f1") + arktest.assertEQ(global_f3.name, "global_f3") + + let f1: Function = (): void => {} + arktest.assertEQ(f1.name, "f1") + + let f2: Function; + f2 = f1; + arktest.assertEQ(f2.name, "f1") + + let f3: Function; + f3 = (): void => {} + arktest.assertEQ(f3.name, "f3") +} -- Gitee