diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index 79205c2b9ef4908b5a65a8a3d9a6fa979590d993..238e29964c885549ec4945d278564f4c20374105 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -556,7 +556,8 @@ void ETSChecker::IterateInVariableContext(varbinder::Variable *const var) } ES2PANDA_ASSERT(classDef->TsType()); - if (!containingClass->IsTypeError()) { + // Note: find the classType of the nearest classScope and then set it as the containingClass. + if (!containingClass->IsTypeError() && Context().ContainingClass() == nullptr) { Context().SetContainingClass(containingClass->AsETSObjectType()); } } diff --git a/ets2panda/test/runtime/ets/namespaceClassPropertyAssignTest.ets b/ets2panda/test/runtime/ets/namespaceClassPropertyAssignTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..1b4aec9afde61661c79519dee5c6f67787928f0c --- /dev/null +++ b/ets2panda/test/runtime/ets/namespaceClassPropertyAssignTest.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +namespace ns { + export interface A { + a: int; + f: () => void; + } + + export class AC implements A { + a: int = 100; + f: () => void = (): void => { + this.a = 200 + } + } +} + +let ac: ns.AC = new ns.AC(); +ac.f(); +arktest.assertEQ(ac.a, 200)