From 00ac7344004774b41b78573cbc6b29b28dca22eb Mon Sep 17 00:00:00 2001 From: yp9522 Date: Mon, 14 Jul 2025 14:18:34 +0800 Subject: [PATCH] const_recursive_function Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICJDIT Signed-off-by: yp9522 --- ets2panda/checker/ETSAnalyzer.cpp | 7 ++++++ .../runtime/ets/const_recursive_function.ets | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 ets2panda/test/runtime/ets/const_recursive_function.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index fb821fb423..a6d6577352 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1082,6 +1082,13 @@ checker::Type *ETSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const } auto *signature = expr->Function()->Signature(); + if (expr->Parent()->IsClassProperty()) { + auto *catchVar = expr->Parent()->AsClassProperty()->AsClassElement()->Key()->AsIdentifier()->Variable(); + if (catchVar!= nullptr && catchVar->TsType() == nullptr) { + catchVar->SetTsType(checker->CreateETSArrowType(signature)); + } + } + checker->Context().SetContainingSignature(signature); expr->Function()->Body()->Check(checker); diff --git a/ets2panda/test/runtime/ets/const_recursive_function.ets b/ets2panda/test/runtime/ets/const_recursive_function.ets new file mode 100644 index 0000000000..5d7950daae --- /dev/null +++ b/ets2panda/test/runtime/ets/const_recursive_function.ets @@ -0,0 +1,25 @@ +/* + * 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. + */ + +const calculateFibonacci = (n: number): number => { + if (n === 0 || n === 1) { + return n + } else { + return calculateFibonacci(n - 1) + calculateFibonacci(n - 2) + } +} + +const result = calculateFibonacci(9) +arktest.assertEQ(result, 34); -- Gitee