Skip to content

Commit da96079

Browse files
committed
[ImportResolution] Don't deduplicate scoped imports
This fixes a few tests that were failing because scoped imports were counted as having imported the module already, leading to later imports of the same module being skipped. Since the scoped imports don't import the full module, this would result in syntactically imported symbols not being found by the compiler.
1 parent 8a6b7f0 commit da96079

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/Sema/ImportResolution.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,18 @@ void ImportResolver::bindImport(UnboundImport &&I) {
385385

386386
I.validateOptions(topLevelModule, SF);
387387

388-
if (!M->isNonSwiftModule() || topLevelModule != M ||
389-
seenClangTLMs.insert(M).second) {
388+
auto alreadyImportedTLM = [ID,this](const ModuleDecl *MD) {
389+
assert(!MD->findUnderlyingClangModule()->isSubModule());
390+
// Scoped imports don't import all symbols from the module, so a scoped
391+
// import does not count the module as imported
392+
if (ID && isScopedImportKind(ID.get()->getImportKind()))
393+
return false;
394+
return !seenClangTLMs.insert(MD).second;
395+
};
396+
if (!M->isNonSwiftModule() || topLevelModule != M || !alreadyImportedTLM(M)) {
390397
addImport(I, M);
391398
if (topLevelModule && topLevelModule != M &&
392-
seenClangTLMs.insert(topLevelModule.get()).second) {
399+
!alreadyImportedTLM(topLevelModule.get())) {
393400
// If we have distinct submodule and top-level module, add both.
394401
// Importing the submodule ensures that it gets loaded, but the decls
395402
// are imported to the TLM, so import that for visibility.

0 commit comments

Comments
 (0)