diff --git a/ets2panda/parser/ETSparserAnnotations.cpp b/ets2panda/parser/ETSparserAnnotations.cpp index 1194431c6943fda737dfb374414c7a1b38799bd9..4f0826d3a9b99cf76b2b9eff1b2231b19eb4713a 100644 --- a/ets2panda/parser/ETSparserAnnotations.cpp +++ b/ets2panda/parser/ETSparserAnnotations.cpp @@ -19,6 +19,7 @@ #include "ir/ets/etsTuple.h" #include "ir/ets/etsUnionType.h" #include "ir/statements/annotationDeclaration.h" +#include "ir/brokenTypeNode.h" namespace ark::es2panda::parser { @@ -195,6 +196,8 @@ ir::AstNode *ETSParser::ParseAnnotationProperty(ir::Identifier *fieldName, ir::M if (typeAnnotation == nullptr && (memberModifiers & ir::ModifierFlags::ANNOTATION_DECLARATION) != 0 && !fieldName->IsErrorPlaceHolder()) { LogError(diagnostic::MISSING_TYPE_ANNOTATION, {fieldName->Name().Mutf8()}, Lexer()->GetToken().Start()); + typeAnnotation = Allocator()->New(Allocator()); + typeAnnotation->SetRange({endLoc, endLoc}); } if (typeAnnotation != nullptr) { diff --git a/ets2panda/test/ast/parser/ets/anno_interface_invalid_error.ets b/ets2panda/test/ast/parser/ets/anno_interface_invalid_error.ets index f8549d009358117bff9f746d9bc5c1b29952d70c..e7656e6b36c9d723693d25cd04240b051c8f41c8 100644 --- a/ets2panda/test/ast/parser/ets/anno_interface_invalid_error.ets +++ b/ets2panda/test/ast/parser/ets/anno_interface_invalid_error.ets @@ -47,3 +47,4 @@ class C{ /* @@? 29:4 Error SyntaxError: Missing type annotation for property 'b'. */ /* @@? 42:11 Error SyntaxError: Only constant expression is expected in the field */ +/* @@? 44:16 Error TypeError: Invalid annotation field type. Only numeric, boolean, string, enum, or arrays of these types are permitted for annotation fields. */ diff --git a/ets2panda/test/ast/parser/ets/declare_annotation.ets b/ets2panda/test/ast/parser/ets/declare_annotation.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba73fcc9baeb39b9f037ef4395bdaca852d3a71b --- /dev/null +++ b/ets2panda/test/ast/parser/ets/declare_annotation.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. + */ + +@interface ClassAuthor { + au`horName: string = "1" +} + +class A{ + @ClassAuthor + foo1(){} + + @ClassAuthor("11") + foo2(){} + + @ClassAuthor({authorName: "22"}) + foo3() + +/* @@? 17:7 Error SyntaxError: Missing type annotation for property 'au'. */ +/* @@? 17:7 Error SyntaxError: Identifier expected, got '`'. */ +/* @@? 21:6 Error TypeError: The required field 'au' must be specified. Fields without default values cannot be omitted. */ +/* @@? 24:6 Error TypeError: Annotation 'ClassAuthor' requires multiple fields to be specified. */ +/* @@? 24:18 Error TypeError: Invalid annotation field type. Only numeric, boolean, string, enum, or arrays of these types are permitted for annotation fields. */ +/* @@? 27:6 Error TypeError: The required field 'au' must be specified. Fields without default values cannot be omitted. */ +/* @@? 27:19 Error TypeError: The parameter 'authorName' does not match any declared property in the annotation 'ClassAuthor'. */ +/* @@? 28:9 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 39:1 Error SyntaxError: Expected '}', got 'end of stream'. */