diff --git a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp index b215a47e80c574e68c599f9d7163f878bb44299e..30fa057f9c4ba0725d0a5e59053531287ccd744d 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 0000000000000000000000000000000000000000..97ecfc8882034cfedc2b3a7fa11f6f31b299fbde --- /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") +}