From 6481ec61215b42e8a6a0469d942ca78ce8093a9d Mon Sep 17 00:00:00 2001 From: huyunhui Date: Mon, 7 Jul 2025 14:52:43 +0800 Subject: [PATCH] Fix bug of annotation Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICKHGT Signed-off-by: huyunhui --- ets2panda/checker/ets/typeCheckingHelpers.cpp | 2 +- .../annotation_usage_wrong_ref.ets | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/parser/ets/annotations_tests/annotation_usage_wrong_ref.ets diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index 182a3fd6f3..939a456667 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -1157,7 +1157,7 @@ void ETSChecker::HandleAnnotationRetention(ir::AnnotationUsage *anno, ir::Annota void ETSChecker::CheckStandardAnnotation(ir::AnnotationUsage *anno) { - if (anno->GetBaseName()->Variable() == nullptr) { + if (anno->GetBaseName()->Variable() == nullptr || IsTypeError(anno->GetBaseName()->TsType())) { return; } ES2PANDA_ASSERT(anno->GetBaseName()->Variable()->Declaration()->Node()->AsAnnotationDeclaration() != nullptr); diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotation_usage_wrong_ref.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotation_usage_wrong_ref.ets new file mode 100644 index 0000000000..6aa297c618 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotation_usage_wrong_ref.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024-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. + */ + +function foo() {} + +@/* @@ label */foo +@interface anno {} + +/* @@@ label Error TypeError: Cannot find type 'foo'. */ \ No newline at end of file -- Gitee