diff --git a/ets2panda/test/ast/compiler/ets/import_export/file1.ets b/ets2panda/test/ast/compiler/ets/import_export/file1.ets new file mode 100644 index 0000000000000000000000000000000000000000..d12297a35d6202ca7091e18a85974513a9fcbd7b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_export/file1.ets @@ -0,0 +1,19 @@ +/* + * 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 default class A {} + +export class B {} \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/import_export/file2.ets b/ets2panda/test/ast/compiler/ets/import_export/file2.ets new file mode 100644 index 0000000000000000000000000000000000000000..3819082f2d2dae1dfb219228d4228099d221924e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_export/file2.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 type { B } from './file1'; +import type { A } from './file1'; + +/* @@? 16:24 Error TypeError: Imported element not exported 'B' */ +/* @@? 17:24 Error TypeError: Imported element not exported 'A' */ +/* @@? 17:24 Error TypeError: Use the default import syntax to import a default exported element */ \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/import_type_without_export.ets b/ets2panda/test/ast/compiler/ets/import_type_without_export.ets index c831615f2abbad58c2f7b45462aae91973378283..883a47d7b168132d9c28231db257183c436ffe3a 100644 --- a/ets2panda/test/ast/compiler/ets/import_type_without_export.ets +++ b/ets2panda/test/ast/compiler/ets/import_type_without_export.ets @@ -17,3 +17,5 @@ import type {A, C} from /* @@ label */'./export_type.ets' let a = new A(); let b = new C(); + +/* @@? 16:39 Error TypeError: Imported element not exported 'C' */ \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/type_binding_01.ets b/ets2panda/test/ast/compiler/ets/type_binding_01.ets index 009b7a28b2430c1efd543177725ffc55592fa502..e09409d73d63f12ea9dc438f0d615e1438569819 100644 --- a/ets2panda/test/ast/compiler/ets/type_binding_01.ets +++ b/ets2panda/test/ast/compiler/ets/type_binding_01.ets @@ -19,3 +19,5 @@ import type {StandardExportedClass as IT1, ClassForExport as IT2} from /* @@ lab function main () { let c1 = new IT1 // compile-time error: cannot create objects of type IT1 } + +/* @@? 17:86 Error TypeError: Imported element not exported 'StandardExportedClass' */ \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/type_binding_02.ets b/ets2panda/test/ast/compiler/ets/type_binding_02.ets index 417f0159e16e714e1b03e214a75041b19ba6b1cc..db6fdb2c1e1bb2b68d452a02f52f77f662c73f33 100644 --- a/ets2panda/test/ast/compiler/ets/type_binding_02.ets +++ b/ets2panda/test/ast/compiler/ets/type_binding_02.ets @@ -19,3 +19,5 @@ import type {StandardExportedClass as IT1, ClassForExport as IT2} from /* @@ lab function main () { let c2 = new IT2 // compile-time error: cannot create objects of type IT2 } + +/* @@? 17:86 Error TypeError: Imported element not exported 'StandardExportedClass' */ \ No newline at end of file diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 06208a27ee572e27f0068793f4bed3115f5166be..461bd6171e1bb899179175745173bfc41fe9e02b 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -1012,8 +1012,12 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(Span re return false; } - ValidateImportVariable(exportNode != nullptr ? exportNode : var->Declaration()->Node(), var->Declaration()->Node(), - imported, importPath); + auto *targetNode = exportNode != nullptr ? exportNode : var->Declaration()->Node(); + if (import->IsTypeKind() && !targetNode->IsExportedType()) { + ThrowError(importPath->Start(), diagnostic::IMPORTED_NOT_EXPORTED, {imported}); + } + + ValidateImportVariable(targetNode, var->Declaration()->Node(), imported, importPath); const auto localName = importSpecifier->Local()->Name(); auto varInGlobalClassScope = Program()->GlobalClassScope()->FindLocal(localName, ResolveBindingOptions::ALL);