From c987b81c981b8e321bade03cdf1b99b27e96e270 Mon Sep 17 00:00:00 2001 From: zmw Date: Fri, 15 Aug 2025 11:08:38 +0800 Subject: [PATCH] Fix invalid syntax assert fail Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICT3K4 Description:Fix invalid syntax assert fail Signed-off-by: zmw --- ets2panda/parser/TypedParser.cpp | 2 +- .../test/ast/compiler/ets/invalid_token.ets | 3 ++- .../ets/invalid_syntax_in_object_literal.ets | 23 +++++++++++++++++++ .../parser/ets/lambda_type_parameter_neg.ets | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/invalid_syntax_in_object_literal.ets diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index 23415ba83e..a6ebafbfc7 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -241,7 +241,7 @@ ir::ArrowFunctionExpression *TypedParser::ParseGenericArrowFunction() ES2PANDA_ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LESS_THAN); lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); - auto typeParamDeclOptions = TypeAnnotationParsingOptions::NO_OPTS; + auto typeParamDeclOptions = TypeAnnotationParsingOptions::REPORT_ERROR; ir::TSTypeParameterDeclaration *typeParamDecl = ParseTypeParameterDeclaration(&typeParamDeclOptions); if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS) { diff --git a/ets2panda/test/ast/compiler/ets/invalid_token.ets b/ets2panda/test/ast/compiler/ets/invalid_token.ets index e7e33126f8..0d30da416f 100644 --- a/ets2panda/test/ast/compiler/ets/invalid_token.ets +++ b/ets2panda/test/ast/compiler/ets/invalid_token.ets @@ -19,4 +19,5 @@ class A { /* @@? 17:18 Error SyntaxError: Number, string or computed value property name '2' is not allowed, use classes to access data by property names that are identifiers */ /* @@? 17:18 Error SyntaxError: Identifier expected, got 'number literal'. */ -/* @@? 17:18 Error SyntaxError: Unexpected token '2'. */ \ No newline at end of file +/* @@? 17:18 Error SyntaxError: Unexpected token '2'. */ +/* @@? 18:1 Error SyntaxError: Unexpected token, expected '>'. */ diff --git a/ets2panda/test/ast/parser/ets/invalid_syntax_in_object_literal.ets b/ets2panda/test/ast/parser/ets/invalid_syntax_in_object_literal.ets new file mode 100644 index 0000000000..11b608f9bc --- /dev/null +++ b/ets2panda/test/ast/parser/ets/invalid_syntax_in_object_literal.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + +let a2: A2 = { + value: { + 'bbb': 222 / '. */ diff --git a/ets2panda/test/ast/parser/ets/lambda_type_parameter_neg.ets b/ets2panda/test/ast/parser/ets/lambda_type_parameter_neg.ets index 51573652ab..27a6cc326f 100644 --- a/ets2panda/test/ast/parser/ets/lambda_type_parameter_neg.ets +++ b/ets2panda/test/ast/parser/ets/lambda_type_parameter_neg.ets @@ -16,6 +16,7 @@ let a = Int>(reader); /* @@? 16:14 Error SyntaxError: Identifier expected, got '('. */ +/* @@? 16:15 Error SyntaxError: Unexpected token, expected '>'. */ /* @@? 16:15 Error SyntaxError: Variable must be initialized or it's type must be declared. */ /* @@? 16:15 Error SyntaxError: Unexpected token ')'. */ /* @@? 16:17 Error SyntaxError: Unexpected token '=>'. */ -- Gitee