From 4b4f100d00000cdab41d7934e569be4593a91023 Mon Sep 17 00:00:00 2001 From: yp9522 Date: Tue, 15 Jul 2025 15:03:20 +0800 Subject: [PATCH] fix CopyAnnotationProperties nullptr Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMF1E Signed-off-by: yp9522 --- .../lowering/ets/annotationCopyLowering.cpp | 3 ++ .../singleField_typeAnnotation_nullptr.ets | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 ets2panda/test/ast/compiler/ets/singleField_typeAnnotation_nullptr.ets diff --git a/ets2panda/compiler/lowering/ets/annotationCopyLowering.cpp b/ets2panda/compiler/lowering/ets/annotationCopyLowering.cpp index 7944383399..63ca3620fa 100644 --- a/ets2panda/compiler/lowering/ets/annotationCopyLowering.cpp +++ b/ets2panda/compiler/lowering/ets/annotationCopyLowering.cpp @@ -43,6 +43,9 @@ 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) { + return; + } auto clone = singleField->TypeAnnotation()->Clone(ctx->Allocator(), param); param->SetTypeAnnotation(clone); return; diff --git a/ets2panda/test/ast/compiler/ets/singleField_typeAnnotation_nullptr.ets b/ets2panda/test/ast/compiler/ets/singleField_typeAnnotation_nullptr.ets new file mode 100755 index 0000000000..c65da1422e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/singleField_typeAnnotation_nullptr.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. + */ + +@Retention("SOURCE") +@interface Retention(nno +()=>{} + +/* @@? 1:3 Error TypeError: Variable 'Retention' is already defined. */ +/* @@? 16:2 Error TypeError: Only standard annotations are allowed to be applied on annotations. */ +/* @@? 16:2 Error TypeError: Annotation 'Retention' requires multiple fields to be specified. */ +/* @@? 17:21 Error SyntaxError: Expected '{', got '('. */ +/* @@? 18:1 Error SyntaxError: Annotation can not have method as property. */ +/* @@? 18:1 Error SyntaxError: Missing type annotation for property 'nno'. */ +/* @@? 18:1 Error SyntaxError: Identifier expected, got '('. */ +/* @@? 18:2 Error SyntaxError: Identifier expected, got ')'. */ +/* @@? 18:3 Error SyntaxError: Identifier expected, got '=>'. */ +/* @@? 18:5 Error SyntaxError: Identifier expected, got '{'. */ +/* @@? 18:6 Error SyntaxError: Identifier expected, got '}'. */ \ No newline at end of file -- Gitee