Skip to content

Commit 229d341

Browse files
committed
Handle module selectors in UDRE lookups
1 parent 5fab496 commit 229d341

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ extension B: @retroactive main::Equatable {
110110
// expected-error@-2 {{cannot infer contextual base in reference to member 'main::min'}}
111111

112112
self = B.main::init(value: .min)
113+
// FIXME improve: expected-error@-1 {{'B' cannot be constructed because it has no accessible initializers}}
114+
// expected-error@-2 {{cannot infer contextual base in reference to member 'min'}}
113115
}
114116

115117
self.main::myNegate()
@@ -144,6 +146,8 @@ extension C: @retroactive ModuleSelectorTestingKit::Equatable {
144146
@_dynamicReplacement(for: ModuleSelectorTestingKit::negate())
145147

146148
mutating func myNegate() {
149+
// FIXME improve: expected-note@-1 {{did you mean 'myNegate'?}}
150+
147151
let fn: (ModuleSelectorTestingKit::Int, ModuleSelectorTestingKit::Int) -> ModuleSelectorTestingKit::Int =
148152
// FIXME improve: expected-error@-1 3{{cannot find type 'ModuleSelectorTestingKit::Int' in scope}}
149153
(ModuleSelectorTestingKit::+)
@@ -161,11 +165,13 @@ extension C: @retroactive ModuleSelectorTestingKit::Equatable {
161165
}
162166
else {
163167
self = ModuleSelectorTestingKit::C(value: .ModuleSelectorTestingKit::min)
168+
// FIXME improve: expected-error@-1 {{type 'Int' has no member 'ModuleSelectorTestingKit::min'}}
164169

165170
self = C.ModuleSelectorTestingKit::init(value: .min)
166171
}
167172

168173
self.ModuleSelectorTestingKit::myNegate()
174+
// FIXME improve: expected-error@-1 {{value of type 'C' has no member 'ModuleSelectorTestingKit::myNegate'}}
169175

170176
ModuleSelectorTestingKit::fatalError()
171177
// FIXME improve: expected-error@-1 {{cannot find 'ModuleSelectorTestingKit::fatalError' in scope}}
@@ -218,9 +224,12 @@ extension D: @retroactive Swift::Equatable {
218224
// expected-error@-2 {{cannot infer contextual base in reference to member 'Swift::min'}}
219225

220226
self = D.Swift::init(value: .min)
227+
// FIXME improve: expected-error@-1 {{'D' cannot be constructed because it has no accessible initializers}}
228+
// expected-error@-2 {{cannot infer contextual base in reference to member 'min'}}
221229
}
222230

223231
self.Swift::myNegate()
232+
// FIXME improve: expected-error@-1 {{value of type 'D' has no member 'Swift::myNegate'}}
224233

225234
Swift::fatalError()
226235
}
@@ -440,6 +449,8 @@ func badModuleNames() {
440449
// expected-error@-1 {{cannot find 'NonexistentModule::print' in scope}}
441450

442451
_ = "foo".NonexistentModule::count
452+
// FIXME improve: expected-error@-1 {{value of type 'String' has no member 'NonexistentModule::count'}}
453+
// FIXME: expected-EVENTUALLY-note@-2 {{did you mean module 'Swift'?}} {{13-30=Swift}}
443454

444455
let x: NonexistentModule::MyType = NonexistentModule::MyType()
445456
// expected-error@-1 {{cannot find type 'NonexistentModule::MyType' in scope}}

0 commit comments

Comments
 (0)