diff --git a/include/swift/AST/Module.h b/include/swift/AST/Module.h index bcd93b2614c92..044bd4ffeb295 100644 --- a/include/swift/AST/Module.h +++ b/include/swift/AST/Module.h @@ -286,7 +286,7 @@ class TranslationUnit : public Module { /// module. This is filled in as the first thing that the Name Binding phase /// does. ArrayRef getImportedModules() const { - assert(ASTStage >= Parsed); + assert(ASTStage >= Parsed || Kind == SIL); return ImportedModules; } void setImportedModules(ArrayRef IM) { diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index f4343f179b3b9..d032d533d47cf 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -893,8 +893,22 @@ bool Module::lookupQualified(Type type, // Look for module references. if (auto moduleTy = type->getAs()) { ModuleLookupCache cache; - lookupInModule(moduleTy->getModule(), {}, name, decls, - NLKind::QualifiedLookup, ResolutionKind::Overloadable, cache); + Module *module = moduleTy->getModule(); + // Perform the lookup in all imports of this module. + forAllVisibleModules(AccessPathTy(), makeStackLambda( + [&](const ImportedModule &import) -> bool { + if (import.second != module) + return true; + lookupInModule(import.second, import.first, name, decls, + NLKind::QualifiedLookup, ResolutionKind::Overloadable, + cache); + // If we're able to do an unscoped lookup, we see everything. No need + // to keep going. + return !import.first.empty(); + })); + std::sort(decls.begin(), decls.end()); + auto afterUnique = std::unique(decls.begin(), decls.end()); + decls.erase(afterUnique, decls.end()); return !decls.empty(); }