diff --git a/ets2panda/ir/statements/annotationUsage.cpp b/ets2panda/ir/statements/annotationUsage.cpp index aee9d75d53ae4433315c6e87f4368bf7c278c708..f15590c6bf9315d47717d30ae8d009fa7bf0c29f 100644 --- a/ets2panda/ir/statements/annotationUsage.cpp +++ b/ets2panda/ir/statements/annotationUsage.cpp @@ -121,6 +121,10 @@ Identifier *AnnotationUsage::GetBaseName() const return expr_->AsIdentifier(); } auto *part = expr_->AsETSTypeReference()->Part(); + if (part->Name()->IsBrokenExpression()) { + return part->Name()->AsIdentifier(); + } + return part->Name()->AsTSQualifiedName()->Right(); } } // namespace ark::es2panda::ir diff --git a/ets2panda/parser/ETSparserAnnotations.cpp b/ets2panda/parser/ETSparserAnnotations.cpp index cdf4dfb5d05b408c149bf73bba8ab6c6bf43c8ec..704e79bcd38ba43b0a03b849ebcdea651afb71aa 100644 --- a/ets2panda/parser/ETSparserAnnotations.cpp +++ b/ets2panda/parser/ETSparserAnnotations.cpp @@ -373,6 +373,10 @@ static lexer::SourcePosition GetExpressionEndLoc(ir::Expression *expr) return expr->AsIdentifier()->End(); } auto *part = expr->AsETSTypeReference()->Part(); + if (part->Name()->IsBrokenExpression()) { + return part->Name()->AsIdentifier()->End(); + } + return part->Name()->AsTSQualifiedName()->Right()->End(); } diff --git a/ets2panda/test/ast/compiler/ets/annotation_dot_with_empty.ets b/ets2panda/test/ast/compiler/ets/annotation_dot_with_empty.ets new file mode 100644 index 0000000000000000000000000000000000000000..04581adbe9bc262665055db4ad73b3313a10c0be --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/annotation_dot_with_empty.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. + */ + +class MyTest { + @Consume. + private property1; +} + +/* @@? 18:5 Error SyntaxError: Identifier expected. */ +/* @@? 18:5 Error TypeError: '*ERROR_LITERAL*' is not an annotation. */ +/* @@? 18:22 Error SyntaxError: Field type annotation expected. */