From 201783d5171728b52cc8478ca5b1a7a1f6c8aa7e Mon Sep 17 00:00:00 2001 From: lixl9 Date: Thu, 17 Jul 2025 16:53:35 +0800 Subject: [PATCH] Fix the annotation end with a dot crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICN0OS Signed-off-by: lixinglong --- ets2panda/parser/ETSparserAnnotations.cpp | 6 ++- .../ambient_annotations_bad_type04.ets | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/annotation_tests/ambient_annotations_bad_type04.ets diff --git a/ets2panda/parser/ETSparserAnnotations.cpp b/ets2panda/parser/ETSparserAnnotations.cpp index cdf4dfb5d0..93b128a161 100644 --- a/ets2panda/parser/ETSparserAnnotations.cpp +++ b/ets2panda/parser/ETSparserAnnotations.cpp @@ -69,7 +69,11 @@ ir::Expression *ETSParser::ParseAnnotationName() auto opt = TypeAnnotationParsingOptions::NO_OPTS; expr = ParseTypeReference(&opt); ES2PANDA_ASSERT(expr != nullptr); - setAnnotation(expr->AsETSTypeReference()->Part()->GetIdent()); + ir::ETSTypeReferencePart *part = expr->AsETSTypeReference()->Part(); + if (part->Name()->IsIdentifier() && part->Name()->AsIdentifier()->IsErrorPlaceHolder() && !IS_USAGE) { + return AllocBrokenExpression(Lexer()->GetToken().Start()); + } + setAnnotation(part->GetIdent()); } else { expr = ExpectIdentifier(); ES2PANDA_ASSERT(expr != nullptr); diff --git a/ets2panda/test/ast/compiler/ets/annotation_tests/ambient_annotations_bad_type04.ets b/ets2panda/test/ast/compiler/ets/annotation_tests/ambient_annotations_bad_type04.ets new file mode 100644 index 0000000000..76f6f43ff3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/annotation_tests/ambient_annotations_bad_type04.ets @@ -0,0 +1,38 @@ +/* + * 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. + */ + +@Retention("SOURCE") +@interface Messagee. +{ + msg: string = "" + id: int +} + +@Retention("SOURCE") +@interface Anno{} + +// annotations for elementType of array +let array("S: @Anno Int[][] +let deepArray: @Anno Number[][][][][] + +function main() {} + +/* @@? 18:1 Error SyntaxError: Identifier expected. */ +/* @@? 27:10 Error SyntaxError: Variable must be initialized or it's type must be declared. */ +/* @@? 27:10 Error SyntaxError: Unexpected token '('. */ +/* @@? 27:11 Error SyntaxError: Newline is not allowed in strings */ +/* @@? 27:28 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 27:28 Error SyntaxError: Unexpected token 'deepArray'. */ +/* @@? 27:28 Error SyntaxError: Label must be followed by a loop statement. */ -- Gitee