From 4ee6022e6d584089b1abce9aa822fa9585125738 Mon Sep 17 00:00:00 2001 From: yp9522 Date: Wed, 16 Jul 2025 14:56:12 +0800 Subject: [PATCH] Fix checkallconstpropertyinitialized nullptr Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMP4L Signed-off-by: yp9522 --- ets2panda/checker/ETSAnalyzerHelpers.cpp | 9 ++++++-- .../test/ast/compiler/ets/xgc_ea/xgc_ea.ets | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100755 ets2panda/test/ast/compiler/ets/xgc_ea/xgc_ea.ets diff --git a/ets2panda/checker/ETSAnalyzerHelpers.cpp b/ets2panda/checker/ETSAnalyzerHelpers.cpp index 644bdb35c6..edad41cf4f 100644 --- a/ets2panda/checker/ETSAnalyzerHelpers.cpp +++ b/ets2panda/checker/ETSAnalyzerHelpers.cpp @@ -816,8 +816,13 @@ void CheckAllConstPropertyInitialized(checker::ETSChecker *checker, ir::ETSModul continue; } - if (prop->AsClassProperty()->Key()->Variable()->HasFlag(varbinder::VariableFlags::INIT_IN_STATIC_BLOCK) && - !prop->AsClassProperty()->Key()->Variable()->HasFlag(varbinder::VariableFlags::INITIALIZED)) { + auto *classProp = prop->AsClassProperty(); + if (classProp->Key()->Variable() == nullptr) { + continue; + } + + if (classProp->Key()->Variable()->HasFlag(varbinder::VariableFlags::INIT_IN_STATIC_BLOCK) && + !classProp->Key()->Variable()->HasFlag(varbinder::VariableFlags::INITIALIZED)) { checker->LogError(diagnostic::MISSING_INIT_FOR_CONST_PACKAGE_PROP, {}, prop->Start()); } } diff --git a/ets2panda/test/ast/compiler/ets/xgc_ea/xgc_ea.ets b/ets2panda/test/ast/compiler/ets/xgc_ea/xgc_ea.ets new file mode 100755 index 0000000000..8f1ecd2d78 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/xgc_ea/xgc_ea.ets @@ -0,0 +1,22 @@ +/** + * 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: * + * 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. + */ + +package xgc_ea + +const SHARED_OBJECTS_COUNT: testResult, "test20 $2" + +/* @@? 17:7 Error SyntaxError: Missing initialization for const package property */ +/* @@? 17:29 Error TypeError: Cannot find type 'testResult'. */ +/* @@? 17:41 Error SyntaxError: Identifier expected, got 'string literal'. */ +/* @@? 22:95 Error SyntaxError: Variable must be initialized or it's type must be declared. */ \ No newline at end of file -- Gitee