From c509de62572d652d7c8e67b78d0fe7faec41282f Mon Sep 17 00:00:00 2001 From: daizihan Date: Sat, 9 Aug 2025 20:53:34 +0800 Subject: [PATCH] Fix variable not init bug Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICS75O?from=project-issue Signed-off-by: daizihan --- ets2panda/checker/ets/helpers.cpp | 1 + ets2panda/test/runtime/ets/not_init.ets | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 ets2panda/test/runtime/ets/not_init.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 0dd0f3a067..1c32a0d2a0 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2745,6 +2745,7 @@ ir::ClassProperty *ETSChecker::ClassPropToImplementationProp(ir::ClassProperty * auto classCtx = varbinder::LexicalScope::Enter(VarBinder(), scope); ReInitScopesForTypeAnnotation(this, classProp->TypeAnnotation(), scope); compiler::InitScopesPhaseETS::RunExternalNode(classProp->Value(), VarBinder()); + VarBinder()->AsETSBinder()->ResolveReferencesForScopeWithContext(classProp, scope); return classProp; } diff --git a/ets2panda/test/runtime/ets/not_init.ets b/ets2panda/test/runtime/ets/not_init.ets new file mode 100644 index 0000000000..1ebdf625f0 --- /dev/null +++ b/ets2panda/test/runtime/ets/not_init.ets @@ -0,0 +1,33 @@ +/* + * 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. + */ + +export interface Inter { + intercept: () => Record +} + + +class foo implements Inter { + intercept: () => Record = () => { + let a : Record = {} + a['key'] = 'value'; + return a; + } +} + +function main() { + let f = new foo(); + let a = f.intercept(); + arktest.assertEQ(a['key'], 'value'); +} \ No newline at end of file -- Gitee