diff --git a/ets2panda/parser/ETSparserAnnotations.cpp b/ets2panda/parser/ETSparserAnnotations.cpp index 452d35330ecb2e5e3207a5e5e735ea08865e2e28..1d634cbc64ace5b343669f8d4f105b2f0dc7c1f3 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 0000000000000000000000000000000000000000..76f6f43ff31f978847ed2496710d4d2fc3448ebd --- /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. */