From 9ac5c7f1d487f8c83a18ba4dc5556dd8817fb02a Mon Sep 17 00:00:00 2001 From: fcc Date: Tue, 24 Jun 2025 16:24:45 +0800 Subject: [PATCH] fix crash related to rest parameter Avoid crash related to rest parameter. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICFY21 Signed-off-by: fcc --- ets2panda/checker/ets/function.cpp | 7 +++--- .../ast/compiler/ets/restvar_type_infer.ets | 22 +++++++++++++++++++ .../annotationUsage_bad_param07.ets | 1 + 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/restvar_type_infer.ets diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 167f9e40b2..b725bc4de3 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1377,10 +1377,6 @@ static varbinder::LocalVariable *SetupSignatureParameter(ir::ETSParameterExpress // Should be moved to original ComposeSignatureInfo after AST fix static bool AppendSignatureInfoParam(ETSChecker *checker, SignatureInfo *sigInfo, ir::ETSParameterExpression *param) { - if (param->IsRestParameter()) { - return true; - } - auto variable = SetupSignatureParameter(param, [checker, param]() { if (param->TypeAnnotation() != nullptr) { auto type = param->TypeAnnotation()->GetType(checker); @@ -1399,6 +1395,9 @@ static bool AppendSignatureInfoParam(ETSChecker *checker, SignatureInfo *sigInfo if (variable == nullptr) { // #23134 return false; } + if (param->IsRestParameter()) { + return true; + } sigInfo->params.push_back(variable); if (!param->IsOptional()) { diff --git a/ets2panda/test/ast/compiler/ets/restvar_type_infer.ets b/ets2panda/test/ast/compiler/ets/restvar_type_infer.ets new file mode 100644 index 0000000000..578567a54a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/restvar_type_infer.ets @@ -0,0 +1,22 @@ +/* +* 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 low 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. +*/ + +function main() { + let r1 = ((...args) =>{ return args.length; })(1,2,3); + let r2 = ((a:number, ...args)=> { return args.length; })(1,2,3,4,5) +} + +/* @@? 17:16 Error TypeError: The type of parameter 'args' cannot be inferred */ +/* @@? 18:26 Error TypeError: The type of parameter 'args' cannot be inferred */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param07.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param07.ets index c1e3d6541e..93b781dc7b 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param07.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param07.ets @@ -23,3 +23,4 @@ function foo(@MyAnno ...a/* @@ label */){} /* @@@ label Error SyntaxError: Parameter declaration should have an explicit type annotation. */ /* @@? 22:15 Error TypeError: The required field 'testProperty1' must be specified. Fields without default values cannot be omitted. */ +/* @@? 22:22 Error TypeError: The type of parameter 'a' cannot be inferred */ -- Gitee