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..f5ba4c3944977b8ba069a8d3fb22f42f10783f52 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/import_export/file1.ets @@ -0,0 +1,17 @@ +/* + * 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..01cd224637d9f0a019738a2bbb30a63cbd45aeb2 --- /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 /* @@ label*/'./file1'; +import type { A } from /* @@ label2*/'./file1'; + +/* @@? 16:37 SyntaxError: Type import requires selective binding to define the required imported elements. */ +/* @@? 17:38 SyntaxError: Type import requires selective binding to define the required imported elements. */ +/* @@? 17:38 TypeError: Use the default import syntax to import a default exported element */ \ No newline at end of file diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index ce4d9475a3d4c5fa6e4ce822388bc4fac3dc07ab..92a53ff25ec8eb9601676c2d4b6166dfeea5aa0b 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -871,8 +871,13 @@ std::pair ETSBinder::FindImportDeclIn } void ETSBinder::ValidateImportVariable(const ir::AstNode *node, const util::StringView &imported, - const ir::StringLiteral *const importPath) + const ir::StringLiteral *const importPath, + const ir::ETSImportDeclaration *import) { + bool isTypeImport = import != nullptr && import->IsTypeKind(); + if (isTypeImport && !node->IsExportedType()) { + ThrowError(importPath->Start(), diagnostic::TYPE_IMPORT_MISSING_SELECTIVE_BINDING, {imported}); + } if (node->IsDefaultExported()) { ThrowError(importPath->Start(), diagnostic::DEFAULT_EXPORT_DIRECT_IMPORTED); } else if (!node->IsExported() && !node->IsDefaultExported()) { @@ -978,7 +983,7 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(Span re auto *node = FindNodeInAliasMap(import->ResolvedSource(), imported); - ValidateImportVariable(node != nullptr ? node : var->Declaration()->Node(), imported, importPath); + ValidateImportVariable(node != nullptr ? node : var->Declaration()->Node(), imported, importPath, import); const auto localName = importSpecifier->Local()->Name(); auto varInGlobalClassScope = Program()->GlobalClassScope()->FindLocal(localName, ResolveBindingOptions::ALL); diff --git a/ets2panda/varbinder/ETSBinder.h b/ets2panda/varbinder/ETSBinder.h index 001a02cb105ca954ea4e28036b186085e7d506fb..f82935bf255863c0d3dd1f6ef94186e1592e6a39 100644 --- a/ets2panda/varbinder/ETSBinder.h +++ b/ets2panda/varbinder/ETSBinder.h @@ -174,7 +174,7 @@ public: ir::ImportDefaultSpecifier *importDefaultSpecifier, const ir::ETSImportDeclaration *import); void ValidateImportVariable(const ir::AstNode *node, const util::StringView &imported, - const ir::StringLiteral *const importPath); + const ir::StringLiteral *const importPath, const ir::ETSImportDeclaration *import); Variable *FindImportSpecifiersVariable(const util::StringView &imported, const varbinder::Scope::VariableMap &globalBindings, Span record);