Skip to content

Commit 563e7eb

Browse files
committed
Allow :: as an alias for . in imports
This is a first cut at how imports ought to adopt module selectors.
1 parent 4df138a commit 563e7eb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4693,7 +4693,9 @@ ParserResult<ImportDecl> Parser::parseDeclImport(ParseDeclOptions Flags,
46934693
/*diagnoseDollarPrefix=*/false,
46944694
diag::expected_identifier_in_decl, "import"))
46954695
return nullptr;
4696-
HasNext = consumeIf(tok::period);
4696+
HasNext = consumeIf(tok::period) ||
4697+
(Context.LangOpts.EnableExperimentalModuleSelector &&
4698+
consumeIf(tok::colon_colon));
46974699
} while (HasNext);
46984700

46994701
// Collect all access path components to an import path.

test/NameLookup/module_selector.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
// RUN: %target-typecheck-verify-swift -module-name main -I %S/Inputs -enable-experimental-module-selector
1+
// RUN: %target-typecheck-verify-swift -sdk %clang-importer-sdk -module-name main -I %S/Inputs -enable-experimental-module-selector
22

33
// Make sure the lack of the experimental flag disables the feature:
4-
// RUN: not %target-typecheck-verify-swift -module-name main -I %S/Inputs 2>/dev/null
4+
// RUN: not %target-typecheck-verify-swift -sdk %clang-importer-sdk -module-name main -I %S/Inputs 2>/dev/null
55

66
import ModuleSelectorTestingKit
77

8+
import ctypes::bits // FIXME: ban using :: with submodules?
9+
import struct ModuleSelectorTestingKit::A
10+
811
let magnitude: Never = fatalError()
912

1013
// Test resolution of main:: using `B`

0 commit comments

Comments
 (0)