Skip to content

Commit 3f6a135

Browse files
committed
Handle module selectors in UDRE lookups
1 parent 27bb586 commit 3f6a135

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace {
6060
class LookupResultBuilder {
6161
LookupResult &Result;
6262
DeclContext *DC;
63+
Identifier ModuleSelector;
6364
NameLookupOptions Options;
6465

6566
/// The vector of found declarations.
@@ -72,8 +73,9 @@ namespace {
7273

7374
public:
7475
LookupResultBuilder(LookupResult &result, DeclContext *dc,
75-
NameLookupOptions options)
76-
: Result(result), DC(dc), Options(options) {
76+
Identifier moduleSelector, NameLookupOptions options)
77+
: Result(result), DC(dc), ModuleSelector(moduleSelector), Options(options)
78+
{
7779
if (dc->getASTContext().isAccessControlDisabled())
7880
Options |= NameLookupFlags::IgnoreAccessControl;
7981
}
@@ -83,6 +85,11 @@ namespace {
8385
removeOverriddenDecls(FoundDecls);
8486
removeOverriddenDecls(FoundOuterDecls);
8587

88+
// Remove any declarations excluded by the module selector from the
89+
// found-declarations set.
90+
removeOutOfModuleDecls(FoundDecls, ModuleSelector, DC);
91+
removeOutOfModuleDecls(FoundOuterDecls, ModuleSelector, DC);
92+
8693
// Remove any shadowed declarations from the found-declarations set.
8794
removeShadowedDecls(FoundDecls, DC);
8895
removeShadowedDecls(FoundOuterDecls, DC);
@@ -290,7 +297,7 @@ LookupResult TypeChecker::lookupUnqualified(DeclContext *dc, DeclNameRef name,
290297
UnqualifiedLookupRequest{descriptor}, {});
291298

292299
LookupResult result;
293-
LookupResultBuilder builder(result, dc, options);
300+
LookupResultBuilder builder(result, dc, name.getModuleSelector(), options);
294301
for (auto idx : indices(lookup.allResults())) {
295302
const auto &found = lookup[idx];
296303
// Determine which type we looked through to find this result.
@@ -377,7 +384,7 @@ LookupResult TypeChecker::lookupMember(DeclContext *dc,
377384
// Make sure we've resolved implicit members, if we need them.
378385
namelookup::installSemanticMembersIfNeeded(type, name);
379386

380-
LookupResultBuilder builder(result, dc, options);
387+
LookupResultBuilder builder(result, dc, name.getModuleSelector(), options);
381388
SmallVector<ValueDecl *, 4> lookupResults;
382389
dc->lookupQualified(type, name, loc, subOptions, lookupResults);
383390

test/NameLookup/module_selector.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extension B: main::Equatable {
6767
// expected-error@-4 {{type 'Bool' is not imported through module 'main'}}
6868
// expected-note@-5 {{did you mean module 'Swift'?}} {{56-60=Swift}}
6969
main::fatalError()
70-
// expected-EVENTUALLY-error@-1 {{type 'fatalError' is not imported through module 'main'}}
70+
// expected-EVENTUALLY-error@-1 {{declaration 'fatalError' is not imported through module 'main'}}
7171
// expected-EVENTUALLY-note@-2 {{did you mean module 'Swift'?}} {{4-8=Swift}}
7272
}
7373

@@ -130,7 +130,7 @@ extension ModuleSelectorTestingKit::C: ModuleSelectorTestingKit::Equatable {
130130
// expected-error@-1 {{type 'Bool' is not imported through module 'ModuleSelectorTestingKit'}}
131131
// expected-note@-2 {{did you mean module 'Swift'?}} {{94-117=Swift}}
132132
ModuleSelectorTestingKit::fatalError()
133-
// expected-EVENTUALLY-error@-1 {{type 'fatalError' is not imported through module 'main'}}
133+
// expected-EVENTUALLY-error@-1 {{declaration 'fatalError' is not imported through module 'ModuleSelectorTestingKit'}}
134134
// expected-EVENTUALLY-note@-2 {{did you mean module 'Swift'?}} {{4-8=Swift}}
135135
}
136136

@@ -139,6 +139,8 @@ extension ModuleSelectorTestingKit::C: ModuleSelectorTestingKit::Equatable {
139139

140140
@_dynamicReplacement(for: ModuleSelectorTestingKit::negate())
141141
mutating func myNegate() {
142+
// FIXME improve: expected-note@-1 {{did you mean 'myNegate'?}}
143+
142144
let fn: (ModuleSelectorTestingKit::Int, ModuleSelectorTestingKit::Int) -> ModuleSelectorTestingKit::Int =
143145
// expected-error@-1 3{{type 'Int' is not imported through module 'ModuleSelectorTestingKit'}}
144146
// expected-note@-2 {{did you mean module 'Swift'?}} {{14-37=Swift}}
@@ -164,10 +166,11 @@ extension ModuleSelectorTestingKit::C: ModuleSelectorTestingKit::Equatable {
164166
}
165167
else {
166168
self = ModuleSelectorTestingKit::C(value: .ModuleSelectorTestingKit::min)
169+
// FIXME improve: expected-error@-1 {{type 'Int' has no member 'ModuleSelectorTestingKit::min'}}
167170
}
168171

169172
self.ModuleSelectorTestingKit::myNegate()
170-
// expected-EVENTUALLY-error@-2 {{can't find 'myNegate' in ModuleSelectorTestingKit}}
173+
// FIXME improve: expected-error@-1 {{value of type 'C' has no member 'ModuleSelectorTestingKit::myNegate'}}
171174
}
172175

173176
// FIXME: Can we test @convention(witness_method:)?
@@ -199,6 +202,8 @@ extension D: @retroactive Swift::Equatable {
199202
@_dynamicReplacement(for: Swift::negate())
200203
// FIXME improve: expected-error@-1 {{replaced function 'Swift::negate()' could not be found}}
201204
mutating func myNegate() {
205+
// FIXME improve: expected-note@-1 {{did you mean 'myNegate'?}}
206+
202207
let fn: (Swift::Int, Swift::Int) -> Swift::Int =
203208
// FIXME:
204209
(Swift::+)
@@ -221,7 +226,7 @@ extension D: @retroactive Swift::Equatable {
221226
}
222227

223228
self.Swift::myNegate()
224-
// expected-EVENTUALLY-error@-1 {{can't find 'myNegate' in Swift}}
229+
// FIXME improve: expected-error@-1 {{value of type 'D' has no member 'Swift::myNegate'}}
225230
}
226231

227232
// FIXME: Can we test @convention(witness_method:)?

0 commit comments

Comments
 (0)