diff --git a/ets2panda/parser/ETSparserAnnotations.cpp b/ets2panda/parser/ETSparserAnnotations.cpp index f09bc2591f7a76a992c73a027ab8fb83fa5e9a20..2f30f11b71da592323d43eb8dcd95e2219cf8ae9 100644 --- a/ets2panda/parser/ETSparserAnnotations.cpp +++ b/ets2panda/parser/ETSparserAnnotations.cpp @@ -210,6 +210,7 @@ ir::AstNode *ETSParser::ParseAnnotationProperty(ir::Identifier *fieldName, ir::M if (initializer != nullptr && !ValidAnnotationValue(initializer)) { LogError(diagnostic::INVALID_VAL_ANNOTATION_FIELD, {}, savePos); + initializer = AllocBrokenExpression(savePos); } memberModifiers |= ir::ModifierFlags::PUBLIC; diff --git a/ets2panda/test/ast/compiler/ets/this_expr_invalid_call_in_annotation_decl.ets b/ets2panda/test/ast/compiler/ets/this_expr_invalid_call_in_annotation_decl.ets new file mode 100644 index 0000000000000000000000000000000000000000..251a2487d4076c74307fee4229c55aa04231079a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/this_expr_invalid_call_in_annotation_decl.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. + */ + +@interface Anno { + testBools: boolean[] = [ + this.barAttr = 0, + ] +} + +/* @@? 17:28 Error SyntaxError: Invalid value for annotation field, expected a constant literal. */ +/* @@? 17:28 Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer04.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer04.ets index e1434d9663841122e45e3a2cf9595042fc1e4380..b7f5cb1977914ada86792854801e59c7805f9e14 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer04.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer04.ets @@ -18,4 +18,4 @@ } /* @@@ label Error SyntaxError: Invalid value for annotation field, expected a constant literal. */ -/* @@? 17:44 Error TypeError: type String has no property named s */ +/* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer05.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer05.ets index 90ac52450aca5ca05825b6abb9ea083b97afff97..4def2c45b257380a859fb43a42493d833d13f8b5 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer05.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer05.ets @@ -20,4 +20,4 @@ class A{} } /* @@@ label Error SyntaxError: Invalid value for annotation field, expected a constant literal. */ -/* @@? 19:43 Error TypeError: Type 'A' cannot be assigned to type 'String' */ +/* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer06.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer06.ets index be2cfb7042f696fe921d00acfbcb17dd4c2e5d9e..1b3832adb038d510ff10429e1275ddc6f2d2c372 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer06.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer06.ets @@ -20,4 +20,4 @@ class A{} } /* @@@ label Error SyntaxError: Invalid value for annotation field, expected a constant literal. */ -/* @@? 19:43 Error TypeError: Type '(a: Int) => void' cannot be assigned to type 'String' */ +/* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param05.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param05.ets index 5a155bd89adda2a8dec9d079ef43ed0d8cd6f23d..4bf5498aa399c326560e23f6c3c489871aee1f7a 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param05.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param05.ets @@ -22,4 +22,4 @@ class B{} /* @@@ label Error SyntaxError: Invalid value for annotation field, expected a constant literal. */ -/* @@? 21:40 Error TypeError: type String has no property named s */ +/* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */