diff --git a/ets2panda/checker/ETSAnalyzerHelpers.cpp b/ets2panda/checker/ETSAnalyzerHelpers.cpp index 295eaa49b553b6c13d76c64661dd37e793643b17..6579897c613af33f1f9ed73e0e43c45279219514 100644 --- a/ets2panda/checker/ETSAnalyzerHelpers.cpp +++ b/ets2panda/checker/ETSAnalyzerHelpers.cpp @@ -801,8 +801,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..05b98fcb0a68a6c37b33e96200c65aaf43680e4c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/xgc_ea/xgc_ea.ets @@ -0,0 +1,23 @@ +/** + * 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'. */ +/* @@? 17:41 Error SyntaxError: Number, string or computed value property name 'test20 $2' is not allowed, use classes to access data by property names that are identifiers */ +/* @@? 23:95 Error SyntaxError: Variable must be initialized or it's type must be declared. */ \ No newline at end of file