From 683746b5ba37b0036c67938ea0be77c9d3bb3745 Mon Sep 17 00:00:00 2001 From: oh-rgx Date: Fri, 1 Aug 2025 09:41:38 +0800 Subject: [PATCH] Fix copy annoProp crash Issue: #ICQ94F Signed-off-by: oh-rgx --- .../lowering/ets/annotationCopyLowering.cpp | 4 +++ .../ast/compiler/ets/annotation_usage.ets | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/annotation_usage.ets diff --git a/ets2panda/compiler/lowering/ets/annotationCopyLowering.cpp b/ets2panda/compiler/lowering/ets/annotationCopyLowering.cpp index 7944383399..fd417695f6 100644 --- a/ets2panda/compiler/lowering/ets/annotationCopyLowering.cpp +++ b/ets2panda/compiler/lowering/ets/annotationCopyLowering.cpp @@ -43,6 +43,10 @@ void CopyAnnotationProperties(public_lib::Context *ctx, ir::AnnotationUsage *st) st->Properties().front()->AsClassProperty()->Id()->Name() == compiler::Signatures::ANNOTATION_KEY_VALUE) { auto *param = st->Properties().front()->AsClassProperty(); auto singleField = annoDecl->Properties().front()->AsClassProperty(); + if (singleField == nullptr || singleField->TypeAnnotation() == nullptr) { + // Will be handled in Checker + return; + } auto clone = singleField->TypeAnnotation()->Clone(ctx->Allocator(), param); param->SetTypeAnnotation(clone); return; diff --git a/ets2panda/test/ast/compiler/ets/annotation_usage.ets b/ets2panda/test/ast/compiler/ets/annotation_usage.ets new file mode 100644 index 0000000000..12997518c1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/annotation_usage.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ + +enum Color {Blue, Green, Red} + +@interface MyValue { + "app.string.confirm" +} + +@MyValue(Color.Blue) +class MyTest { + @MyValue(Color.Green) + foo() {} +} + +/* @@? 19:5 Error SyntaxError: Number, string or computed value property name 'app.string.confirm' is not allowed, use classes to access data by property names that are identifiers */ +/* @@? 19:5 Error SyntaxError: Identifier expected, got 'string literal'. */ +/* @@? 20:1 Error SyntaxError: Identifier expected, got '}'. */ -- Gitee