From 00363cd1745b48a2fe502b5ad12eb133d4633b00 Mon Sep 17 00:00:00 2001 From: daizihan Date: Thu, 28 Aug 2025 16:01:10 +0800 Subject: [PATCH] Fix crash in default parameter in lambda Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICV905?from=project-issue Signed-off-by: daizihan --- ets2panda/parser/ETSparserExpressions.cpp | 5 +++++ .../ast/compiler/ets/default_param_lambda.ets | 20 +++++++++++++++++++ .../ets/fuzz}/signature_info_param.ets | 14 +++---------- .../srcdumper/srcdumper-ets-ignored.txt | 1 + 4 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/default_param_lambda.ets rename ets2panda/test/{ast/compiler/ets => runtime/ets/fuzz}/signature_info_param.ets (53%) diff --git a/ets2panda/parser/ETSparserExpressions.cpp b/ets2panda/parser/ETSparserExpressions.cpp index f1cd269a67..9b7dc49103 100644 --- a/ets2panda/parser/ETSparserExpressions.cpp +++ b/ets2panda/parser/ETSparserExpressions.cpp @@ -74,6 +74,11 @@ ir::Expression *ETSParser::ParseFunctionParameterExpression(ir::AnnotatedExpress std::string value = GetArgumentsSourceView(Lexer(), lexerPos); paramExpression->SetLexerSaved(util::UString(value, Allocator()).View()); paramExpression->SetRange({paramIdent->Start(), paramExpression->Initializer()->End()}); + + if (paramIdent->TypeAnnotation() == nullptr && defaultValue != nullptr) { + LogError(diagnostic::EXPLICIT_PARAM_TYPE, util::DiagnosticMessageParams {}, paramIdent->Start()); + paramExpression->SetInitializer(nullptr); + } } else if (paramIdent->IsIdentifier()) { paramExpression = AllocNode(paramIdent->AsIdentifier(), isOptional, Allocator()); ES2PANDA_ASSERT(paramExpression != nullptr); diff --git a/ets2panda/test/ast/compiler/ets/default_param_lambda.ets b/ets2panda/test/ast/compiler/ets/default_param_lambda.ets new file mode 100644 index 0000000000..278627b0f1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/default_param_lambda.ets @@ -0,0 +1,20 @@ +/* + * 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 main() { + let f : (a: string) => void = (/* @@ label */a = "aaa") => {} +} + +/* @@@ label Error SyntaxError: Parameter declaration should have an explicit type annotation. */ diff --git a/ets2panda/test/ast/compiler/ets/signature_info_param.ets b/ets2panda/test/runtime/ets/fuzz/signature_info_param.ets similarity index 53% rename from ets2panda/test/ast/compiler/ets/signature_info_param.ets rename to ets2panda/test/runtime/ets/fuzz/signature_info_param.ets index 86eadbdc4a..9eca0036f8 100644 --- a/ets2panda/test/ast/compiler/ets/signature_info_param.ets +++ b/ets2panda/test/runtime/ets/fuzz/signature_info_param.ets @@ -12,19 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/*--- + tags: [compile-only, negative] +---*/ function testInfo() : void { let iniP : Promise = intFunc(); let pThen = iniP.then((d = e : Object) : Object => { return else;}); } - -/* @@? 17:34 Error TypeError: Unresolved reference intFunc */ -/* @@? 18:34 Error SyntaxError: Unexpected token, expected ',' or ')'. */ -/* @@? 18:42 Error SyntaxError: Expected '=>', got ')'. */ -/* @@? 18:42 Error SyntaxError: Unexpected token ')'. */ -/* @@? 18:44 Error SyntaxError: Unexpected token, expected ',' or ')'. */ -/* @@? 18:44 Error SyntaxError: Unexpected token ':'. */ -/* @@? 18:46 Error SyntaxError: Unexpected token 'Object'. */ -/* @@? 18:46 Error TypeError: The type of parameter 'Object' cannot be inferred */ -/* @@? 18:65 Error SyntaxError: Unexpected token 'else'. */ -/* @@? 18:71 Error SyntaxError: Unexpected token ')'. */ diff --git a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt index 8b3eeeb395..8eb1ec055c 100644 --- a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt +++ b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt @@ -42,6 +42,7 @@ runtime/ets/StringFasta.ets runtime/ets/struct-identifier.ets runtime/ets/struct-init2.ets runtime/ets/fuzz/empty_variable.ets +runtime/ets/fuzz/signature_info_param.ets runtime/ets/fuzz/too_many_minus.ets runtime/ets/fuzz/too_many_plus.ets runtime/ets/fuzz/too_many_plus_1.ets -- Gitee