From 1ef29edfed998f96a9198c42f721274ffc36ee71 Mon Sep 17 00:00:00 2001 From: zmw Date: Fri, 11 Jul 2025 17:33:56 +0800 Subject: [PATCH] Fix invalid option param crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLR4Q Description: Fix invalid option param crash Signed-off-by: zmw --- ets2panda/checker/ets/function.cpp | 4 ++- .../ast/compiler/ets/invalid_option_param.ets | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/invalid_option_param.ets diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 40a06e17af..3d4ca8c018 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1584,9 +1584,11 @@ static bool AppendSignatureInfoParam(ETSChecker *checker, SignatureInfo *sigInfo return checker->GlobalTypeError(); }()); - if (variable == nullptr) { // #23134 + if (variable == nullptr || + (!checker->HasStatus(checker::CheckerStatus::IN_TYPE_INFER) && variable->TsType()->IsTypeError())) { // #23134 return false; } + if (param->IsRestParameter()) { return true; } diff --git a/ets2panda/test/ast/compiler/ets/invalid_option_param.ets b/ets2panda/test/ast/compiler/ets/invalid_option_param.ets new file mode 100644 index 0000000000..34c5ae324f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/invalid_option_param.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. + */ + +function check(test? String): void { } + +/* @@? 16:10 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 16:16 Error TypeError: The type of parameter 'test' cannot be inferred */ +/* @@? 16:22 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 16:22 Error SyntaxError: Class cannot be used as object. */ +/* @@? 16:28 Error SyntaxError: Unexpected token ')'. */ +/* @@? 16:29 Error SyntaxError: Unexpected token ':'. */ +/* @@? 16:31 Error SyntaxError: Unexpected token 'void'. */ +/* @@? 16:36 Error SyntaxError: Unexpected token '{'. */ -- Gitee