Skip to content

Commit 3218bb7

Browse files
committed
Handle module selectors in UDRE lookups
1 parent 864ba8b commit 3218bb7

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace {
3333
class LookupResultBuilder {
3434
LookupResult &Result;
3535
DeclContext *DC;
36+
Identifier ModuleSelector;
3637
NameLookupOptions Options;
3738

3839
/// The vector of found declarations.
@@ -45,8 +46,9 @@ namespace {
4546

4647
public:
4748
LookupResultBuilder(LookupResult &result, DeclContext *dc,
48-
NameLookupOptions options)
49-
: Result(result), DC(dc), Options(options) {
49+
Identifier moduleSelector, NameLookupOptions options)
50+
: Result(result), DC(dc), ModuleSelector(moduleSelector), Options(options)
51+
{
5052
if (dc->getASTContext().isAccessControlDisabled())
5153
Options |= NameLookupFlags::IgnoreAccessControl;
5254
}
@@ -56,6 +58,11 @@ namespace {
5658
removeOverriddenDecls(FoundDecls);
5759
removeOverriddenDecls(FoundOuterDecls);
5860

61+
// Remove any declarations excluded by the module selector from the
62+
// found-declarations set.
63+
removeOutOfModuleDecls(FoundDecls, ModuleSelector, DC);
64+
removeOutOfModuleDecls(FoundOuterDecls, ModuleSelector, DC);
65+
5966
// Remove any shadowed declarations from the found-declarations set.
6067
removeShadowedDecls(FoundDecls, DC);
6168
removeShadowedDecls(FoundOuterDecls, DC);
@@ -245,7 +252,7 @@ LookupResult TypeChecker::lookupUnqualified(DeclContext *dc, DeclNameRef name,
245252
UnqualifiedLookupRequest{descriptor}, {});
246253

247254
LookupResult result;
248-
LookupResultBuilder builder(result, dc, options);
255+
LookupResultBuilder builder(result, dc, name.getModuleSelector(), options);
249256
for (auto idx : indices(lookup.allResults())) {
250257
const auto &found = lookup[idx];
251258
// Determine which type we looked through to find this result.
@@ -348,7 +355,7 @@ LookupResult TypeChecker::lookupMember(DeclContext *dc,
348355
// Make sure we've resolved implicit members, if we need them.
349356
installSemanticMembersIfNeeded(type, name);
350357

351-
LookupResultBuilder builder(result, dc, options);
358+
LookupResultBuilder builder(result, dc, name.getModuleSelector(), options);
352359
SmallVector<ValueDecl *, 4> lookupResults;
353360
dc->lookupQualified(type, name, subOptions, lookupResults);
354361

test/NameLookup/module_selector.swift

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

@@ -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:)?
@@ -181,7 +184,7 @@ extension Swift::D {}
181184
// expected-note@-2 {{did you mean module 'ModuleSelectorTestingKit'?}} {{11-16=ModuleSelectorTestingKit}}
182185

183186
extension D: Swift::Equatable {
184-
// FIXME wat: expected-error@-1 {{implementation of 'Equatable' cannot be automatically synthesized in an extension in a different file to the type}}
187+
// FIXME wat: expected-error@-1 *{{implementation of 'Equatable' cannot be automatically synthesized in an extension in a different file to the type}}
185188

186189
@_implements(Swift::Equatable, Swift::==(_:_:))
187190
// expected-error@-1 {{name cannot be qualified with module selector here}} {{34-41=}}
@@ -199,6 +202,8 @@ extension D: 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::+)
@@ -220,7 +225,7 @@ extension D: Swift::Equatable {
220225
}
221226

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

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

0 commit comments

Comments
 (0)