diff --git a/ets2panda/checker/ETSAnalyzerHelpers.cpp b/ets2panda/checker/ETSAnalyzerHelpers.cpp index 644bdb35c6861e667ed1bb1c5736a11d153ffa8b..edad41cf4f368826291482b07fe103c0541ab443 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 0000000000000000000000000000000000000000..8f1ecd2d7822d6f41ea2a04bee41a39b35afffb9 --- /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