Skip to content

Commit

Permalink
Properly ignore declarations not within the access path of a scoped i…
Browse files Browse the repository at this point in the history
…mport.

We now handle this correctly:
  import struct aeiou.A
  import struct aeiou.E

  var _ : aeiou.O // error

Swift SVN r7046
  • Loading branch information
jrose-apple committed Aug 8, 2013
1 parent f877661 commit 841e3f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class TranslationUnit : public Module {
/// module. This is filled in as the first thing that the Name Binding phase
/// does.
ArrayRef<ImportedModule> getImportedModules() const {
assert(ASTStage >= Parsed);
assert(ASTStage >= Parsed || Kind == SIL);
return ImportedModules;
}
void setImportedModules(ArrayRef<ImportedModule> IM) {
Expand Down
18 changes: 16 additions & 2 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,22 @@ bool Module::lookupQualified(Type type,
// Look for module references.
if (auto moduleTy = type->getAs<ModuleType>()) {
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();
}

Expand Down

0 comments on commit 841e3f4

Please sign in to comment.