diff --git a/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/export_file.ets b/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/export_file.ets new file mode 100644 index 0000000000000000000000000000000000000000..e5c45ec62b539666b5ab58d44666a02d16fab571 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/export_file.ets @@ -0,0 +1,16 @@ +/* + * 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 class Host {} \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/scope_import_1.ets b/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/scope_import_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6843e6780a276d26096a0d9f027689546df13a9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/scope_import_1.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. + */ + +namespace ns { + import * as nsi from './export_file'; +} + +/* @@? 17:5 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ +/* @@? 17:12 Error TypeError: Variable 'nsi' has already been declared. */ diff --git a/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/scope_import_2.ets b/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/scope_import_2.ets new file mode 100644 index 0000000000000000000000000000000000000000..e5dbc4c1f517123bb55f636e2cdd5ab72f676817 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/scope_import_2.ets @@ -0,0 +1,22 @@ +/* + * 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 main() { + { + import * as sci from './export_file'; + } +} + +/* @@? 18:9 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ diff --git a/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/scope_import_3.ets b/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/scope_import_3.ets new file mode 100644 index 0000000000000000000000000000000000000000..b57db803922961286b25b776ce62bdd26c10b8da --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_tests/import_within_scope/scope_import_3.ets @@ -0,0 +1,22 @@ +/* + * 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 main() { + if (true) { + import * as ici from './export_file'; + } +} + +/* @@? 18:9 Error SyntaxError: Import declarations can only be used on the top level and before any other declaration, top level statement or directive. */ \ No newline at end of file diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index 4625e5f011d23cce9335194492f80587e2da3073..f6888b5055bef81b8600af89cbb2bb719e29402f 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -869,6 +869,10 @@ Variable *ClassScope::FindLocal(const util::StringView &name, ResolveBindingOpti void ClassScope::SetBindingProps(Decl *newDecl, BindingProps *props, bool isStatic) { + if (newDecl->IsImportDecl()) { + return; + } + switch (newDecl->Type()) { case DeclType::CONST: [[fallthrough]];