diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp index 79c7e937fbeece7e49a37046bf597c1b93d00402..f20c61b7208fa002d81e7af2f16c59ca6d5209b9 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp @@ -408,6 +408,7 @@ void GlobalClassHandler::SetupGlobalClass(const ArenaVector & globalDecl->SetParent(globalProgram->Ast()); globalClass->SetGlobalInitialized(); CollectProgramGlobalClasses(globalProgram, namespaces); + TransformBrokenNamespace(globalProgram->Ast(), globalProgram); auto initializerBlockStmts = FormInitStaticBlockMethodStatements(globalProgram, moduleDependencies, std::move(initializerBlock)); CollectExportedClasses(globalProgram, globalClass, globalProgram->Ast()->Statements()); diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 7c01ae71d99b5d4c4b9c82cd26fb104174d7cdc2..fc3315b47dcaf98c92b7197ac4292a1b132ed470 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -578,7 +578,7 @@ ir::AstNode *ETSParser::ParseInnerTypeDeclaration(ir::ModifierFlags memberModifi Lexer()->GetToken().SetTokenType(Lexer()->GetToken().KeywordType()); ir::AstNode *typeDecl = ParseTypeDeclaration(true); if (typeDecl == nullptr) { - return nullptr; + return AllocBrokenStatement({savedPos.GetToken().Start(), Lexer()->GetToken().End()}); } memberModifiers &= (ir::ModifierFlags::PUBLIC | ir::ModifierFlags::PROTECTED | ir::ModifierFlags::PRIVATE | ir::ModifierFlags::INTERNAL); diff --git a/ets2panda/test/ast/compiler/ets/broken_namespace.ets b/ets2panda/test/ast/compiler/ets/broken_namespace.ets new file mode 100644 index 0000000000000000000000000000000000000000..ed45c5f86ddeba27175f5cdd339f9b6b1b6e8a18 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/broken_namespace.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. + */ + +function foo(){ + if(entry != undefined){ + namespace buffer{ + export function bar(){} + } + } +} + +if(entry != undefined){ + namespace buffer{ + export function bar(){} + } +} + +/* @@? 18:9 Error SyntaxError: Namespace is allowed only at the top level or inside a namespace. */ +/* @@? 24:4 Error TypeError: Unresolved reference entry */ +/* @@? 25:5 Error SyntaxError: Namespace is allowed only at the top level or inside a namespace. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/declare_namespace_5.ets b/ets2panda/test/ast/parser/ets/declare_namespace_5.ets index 61605b9c0d41be5e590fd2276c0ed928727e5719..d51789195011e4f5a76ea22c01128aa41778f768 100644 --- a/ets2panda/test/ast/parser/ets/declare_namespace_5.ets +++ b/ets2panda/test/ast/parser/ets/declare_namespace_5.ets @@ -49,6 +49,7 @@ class B { } /* @@? 17:5 Error SyntaxError: Namespace is allowed only at the top level or inside a namespace. */ +/* @@? 18:9 Error TypeError: Unresolved reference dfdfsfdf */ /* @@? 20:5 Error SyntaxError: Namespace is allowed only at the top level or inside a namespace. */ /* @@? 23:20 Error TypeError: Unresolved reference foo */ /* @@? 27:11 Error TypeError: Property 'getInstance' does not exist on type 'B' */