diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index a0628a3398fe73f27387804698ea632c0f31f431..c792501b303ffea9f80121ca402667c01defbe88 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1809,7 +1809,9 @@ ETSObjectType *ETSChecker::CheckThisOrSuperAccess(ir::Expression *node, ETSObjec return classType; } - if (classType->GetDeclNode()->IsClassDefinition() && classType->GetDeclNode()->AsClassDefinition()->IsGlobal()) { + if (classType->GetDeclNode()->IsClassDefinition() && + (classType->GetDeclNode()->AsClassDefinition()->IsGlobal() || + classType->GetDeclNode()->AsClassDefinition()->IsNamespaceTransformed())) { LogError(diagnostic::CTOR_REF_INVALID_CTX_GLOBAL, {msg}, node->Start()); return GlobalBuiltinErrorType(); } diff --git a/ets2panda/test/ast/compiler/ets/invalid_this_in_namespace.ets b/ets2panda/test/ast/compiler/ets/invalid_this_in_namespace.ets new file mode 100644 index 0000000000000000000000000000000000000000..8145aabd6bdb1dec342715a67b5f6ae44e7a49e4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/invalid_this_in_namespace.ets @@ -0,0 +1,20 @@ +/* + * 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 X { + this.toString() +} + +/* @@? 17:5 Error TypeError: Cannot reference 'this' in this context. */