From 6771bf58d910b9fa794a21dc5f39321f753a7a3d 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 Change-Id: Ia5536035b225de9cf495592d45293ac267fd04f0 --- ets2panda/checker/ets/function.cpp | 2 +- .../ast/compiler/ets/invalid_option_param.ets | 28 +++++++++++++++++++ 2 files changed, 29 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 dd2d97fc1d..5fbacc8495 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1317,7 +1317,7 @@ static bool AppendSignatureInfoParam(ETSChecker *checker, SignatureInfo *sigInfo if (!param->IsOptional()) { ++sigInfo->minArgCount; } - ES2PANDA_ASSERT(!param->IsOptional() || + ES2PANDA_ASSERT(!param->IsOptional() || param->IsOptional()->Ident()->TsType()->IsTypeError() || checker->Relation()->IsSupertypeOf(param->Ident()->TsType(), checker->GlobalETSUndefinedType())); 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..a473b4e80a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/invalid_option_param.ets @@ -0,0 +1,28 @@ +/* + * 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 TypeError: Class name 'String' used in the wrong context */ +/* @@? 16:28 Error SyntaxError: Unexpected token ')'. */ +/* @@? 16:28 Error SyntaxError: Unexpected token ')'. */ +/* @@? 16:28 Error SyntaxError: Unexpected token ')'. */ +/* @@? 16:29 Error SyntaxError: Unexpected token ':'. */ +/* @@? 16:29 Error SyntaxError: Unexpected token ':'. */ +/* @@? 16:31 Error SyntaxError: Unexpected token 'void'. */ +/* @@? 16:31 Error SyntaxError: Unexpected token 'void'. */ -- Gitee