From c535214cea001a3083ab4ffac88059c839ea2faf Mon Sep 17 00:00:00 2001 From: huyunhui Date: Wed, 13 Aug 2025 17:26:10 +0800 Subject: [PATCH] Fix bug of namespace import Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICST1M Signed-off-by: huyunhui --- ets2panda/checker/ets/helpers.cpp | 5 ++++ ets2panda/compiler/lowering/util.cpp | 1 + ets2panda/driver/build_system/package.json | 4 ++- .../namespace_import/build_config.json | 25 +++++++++++++++++++ .../namespace_import/entry/a.ets | 18 +++++++++++++ .../namespace_import/entry/b.ets | 21 ++++++++++++++++ .../namespace_import/entry/c.ets | 18 +++++++++++++ ets2panda/parser/program/program.cpp | 5 ++++ ets2panda/parser/program/program.h | 1 + 9 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/build_config.json create mode 100644 ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/a.ets create mode 100644 ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/b.ets create mode 100644 ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/c.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 618cc3ab61..e3fdd3bcce 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1858,8 +1858,13 @@ void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjT if (!VarBinder()->AsETSBinder()->GetGlobalRecordTable()->IsExternal()) { RemoveStatus(CheckerStatus::IN_EXTERNAL); } + auto savedProgram = Program(); + VarBinder()->AsETSBinder()->SetProgram(program); + VarBinder()->AsETSBinder()->ResetTopScope(program->GlobalScope()); program->SetASTChecked(); program->Ast()->Check(this); + VarBinder()->AsETSBinder()->SetProgram(savedProgram); + VarBinder()->AsETSBinder()->ResetTopScope(savedProgram->GlobalScope()); } BindingsModuleObjectAddProperty( diff --git a/ets2panda/compiler/lowering/util.cpp b/ets2panda/compiler/lowering/util.cpp index 84e9ccb559..0bc3bb411e 100644 --- a/ets2panda/compiler/lowering/util.cpp +++ b/ets2panda/compiler/lowering/util.cpp @@ -177,6 +177,7 @@ static bool IsGeneratedDynamicClass(ir::AstNode const *ast) static void ClearHelper(parser::Program *prog) { + prog->RemoveAstChecked(); ResetGlobalClass(prog); // #24256 Should be removed when code refactoring on checker is done and no ast node allocated in checker. auto &stmts = prog->Ast()->StatementsForUpdates(); diff --git a/ets2panda/driver/build_system/package.json b/ets2panda/driver/build_system/package.json index 9ba50d6869..f574bafc48 100644 --- a/ets2panda/driver/build_system/package.json +++ b/ets2panda/driver/build_system/package.json @@ -52,7 +52,9 @@ "build_system_Utest": "jest --testMatch='**/test/ut/**/*.test.ts' --testPathIgnorePatterns='test/e2e/'", "build_system_Etest": "TEST=demo_entry1.2_hsp1.1:gen_abc jest --testMatch='**/test/e2e/*.test.ts' --testPathIgnorePatterns='test/ut/'", "IncrementCompileTest1": "npm run build && node ./dist/entry.js test/e2e/IncrementDemo/build_config.json && sed -i 's/hello world from harA!/hello world from harA! (modified)/' \"$(pwd)/test/e2e/IncrementDemo/harB/index.ets\" && TEST=IncrementDemo:gen_abc jest --testMatch='**/test/e2e/*.test.ts' --testPathIgnorePatterns='test/ut/'", - "IncrementCompileTest2": "npm run build && node ./dist/entry.js test/e2e/IncrementDemo/build_config.json && sed -i 's/console.log(strA)/console.log(strA + \"modified\")/' \"$(pwd)/test/e2e/IncrementDemo/entry/index.ets\" && TEST=IncrementDemo:gen_abc jest --testMatch='**/test/e2e/*.test.ts' --testPathIgnorePatterns='test/ut/'" + "IncrementCompileTest2": "npm run build && node ./dist/entry.js test/e2e/IncrementDemo/build_config.json && sed -i 's/console.log(strA)/console.log(strA + \"modified\")/' \"$(pwd)/test/e2e/IncrementDemo/entry/index.ets\" && TEST=IncrementDemo:gen_abc jest --testMatch='**/test/e2e/*.test.ts' --testPathIgnorePatterns='test/ut/'", + + "simultaneous_compiling:namespace_import": "npm run build && node ./dist/entry.js test/simultaneous_compiling/namespace_import/build_config.json" }, "devDependencies": { "@babel/core": "^7.24.9", diff --git a/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/build_config.json b/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/build_config.json new file mode 100644 index 0000000000..55051283c8 --- /dev/null +++ b/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/build_config.json @@ -0,0 +1,25 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/simultaneous_compiling/namespace_import/entry/a.ets", + "${absolute_path_to_build_system}/test/simultaneous_compiling/namespace_import/entry/b.ets", + "${absolute_path_to_build_system}/test/simultaneous_compiling/namespace_import/entry/c.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/simultaneous_compiling/namespace_import/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/a.ets b/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/a.ets new file mode 100644 index 0000000000..57499604dd --- /dev/null +++ b/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/a.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +import { A } from "./b" + +A() \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/b.ets b/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/b.ets new file mode 100644 index 0000000000..4a4071ec7b --- /dev/null +++ b/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/b.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import * as ns from "./c" + +export function A() { + let a: boolean = ns.falseRes(); + a = a && ns.falseRes(); +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/c.ets b/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/c.ets new file mode 100644 index 0000000000..b980c146f4 --- /dev/null +++ b/ets2panda/driver/build_system/test/simultaneous_compiling/namespace_import/entry/c.ets @@ -0,0 +1,18 @@ +/* + * 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 function falseRes(): boolean { + return false; +} \ No newline at end of file diff --git a/ets2panda/parser/program/program.cpp b/ets2panda/parser/program/program.cpp index f3efae5f7b..2386dc848a 100644 --- a/ets2panda/parser/program/program.cpp +++ b/ets2panda/parser/program/program.cpp @@ -181,6 +181,11 @@ void Program::SetASTChecked() programFlags_ |= ProgramFlags::AST_CHECKED; } +void Program::RemoveAstChecked() +{ + programFlags_ &= ~ProgramFlags::AST_CHECKED; +} + bool Program::IsASTChecked() { return ((programFlags_ & ProgramFlags::AST_CHECKED) != 0U) || diff --git a/ets2panda/parser/program/program.h b/ets2panda/parser/program/program.h index 5056378116..fbb24ddfd2 100644 --- a/ets2panda/parser/program/program.h +++ b/ets2panda/parser/program/program.h @@ -283,6 +283,7 @@ public: void SetFlag(ProgramFlags flag); bool GetFlag(ProgramFlags flag) const; void SetASTChecked(); + void RemoveAstChecked(); bool IsASTChecked(); void MarkASTAsLowered() -- Gitee