From 375249dc43e3fc74986579ddf048992e42f8c6e7 Mon Sep 17 00:00:00 2001 From: zmw Date: Thu, 10 Jul 2025 22:00:05 +0800 Subject: [PATCH] Fix invalid format crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLJ3Q Description: Fix invalid format crash Signed-off-by: zmw --- ets2panda/parser/ETSFormattedParser.cpp | 4 +-- .../parser/ets/invalid_punctuator_format.ets | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/invalid_punctuator_format.ets diff --git a/ets2panda/parser/ETSFormattedParser.cpp b/ets2panda/parser/ETSFormattedParser.cpp index cfda403d427..b2e9c03b74f 100644 --- a/ets2panda/parser/ETSFormattedParser.cpp +++ b/ets2panda/parser/ETSFormattedParser.cpp @@ -106,8 +106,8 @@ ir::TypeNode *ETSParser::ParseTypeFormatPlaceholder(std::optionalGetToken().Start()); - ES2PANDA_UNREACHABLE(); + LogUnexpectedToken(lexer::TokenType::PUNCTUATOR_FORMAT); + return AllocBrokenType(Lexer()->GetToken().Loc()); } nodeFormat = GetFormatPlaceholderType(); diff --git a/ets2panda/test/ast/parser/ets/invalid_punctuator_format.ets b/ets2panda/test/ast/parser/ets/invalid_punctuator_format.ets new file mode 100644 index 00000000000..2eba0019b69 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/invalid_punctuator_format.ets @@ -0,0 +1,27 @@ +/* + * 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. + */ + +interface I { +J* @@? +} + +/* @@? 17:2 Error SyntaxError: Interface fields must have type annotation. */ +/* @@? 17:4 Error SyntaxError: Unexpected token '@@'. */ +/* @@? 17:4 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 17:4 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:6 Error SyntaxError: Identifier expected. */ +/* @@? 17:6 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 17:6 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 18:1 Error SyntaxError: Identifier expected. */ -- Gitee