Skip to content

Commit 61a4a48

Browse files
committed
AST: Add scoped import shadowing rule to removeShadowedDecls()
This simulates the shadowing done by ModuleNameLookup, which is about to be removed. The basic idea is that top-level declarations found via scoped imports take precedence over unscoped imports.
1 parent f567b8f commit 61a4a48

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/AST/NameLookup.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ static void recordShadowedDeclsAfterSignatureMatch(
206206
if (firstModule != secondModule &&
207207
firstDecl->getDeclContext()->isModuleScopeContext() &&
208208
secondDecl->getDeclContext()->isModuleScopeContext()) {
209+
// First, scoped imports shadow unscoped imports.
210+
bool firstScoped = imports.isScopedImport(firstModule, name, dc);
211+
bool secondScoped = imports.isScopedImport(secondModule, name, dc);
212+
if (!firstScoped && secondScoped) {
213+
shadowed.insert(firstDecl);
214+
break;
215+
} else if (firstScoped && !secondScoped) {
216+
shadowed.insert(secondDecl);
217+
continue;
218+
}
219+
209220
// Now check if one module shadows the other.
210221
if (imports.isShadowedBy(firstModule, secondModule, name, dc)) {
211222
shadowed.insert(firstDecl);

test/NameBinding/import-resolution.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ letters.asdf.A // expected-error{{module 'letters' has no member named 'asdf'}}
3232
var uA : A // expected-error {{'A' is ambiguous for type lookup in this context}}
3333
var uB : B = abcde.B()
3434
var uC : C // expected-error {{'C' is ambiguous for type lookup in this context}}
35-
var uD : D // expected-error {{'D' is ambiguous for type lookup in this context}}
36-
var uE : E // expected-error {{'E' is ambiguous for type lookup in this context}}
35+
var uD : D = asdf.D()
36+
var uE : E = aeiou.E()
3737
var uF : F = letters.F()
3838

3939
var qA1 : abcde.A // okay

0 commit comments

Comments
 (0)