Skip to content

Commit 7b6f787

Browse files
committed
Handle module selectors in UDRE lookups
1 parent 7cb3117 commit 7b6f787

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.
@@ -381,7 +388,7 @@ LookupResult TypeChecker::lookupMember(DeclContext *dc,
381388
// Make sure we've resolved implicit members, if we need them.
382389
namelookup::installSemanticMembersIfNeeded(type, name);
383390

384-
LookupResultBuilder builder(result, dc, options);
391+
LookupResultBuilder builder(result, dc, name.getModuleSelector(), options);
385392
SmallVector<ValueDecl *, 4> lookupResults;
386393
dc->lookupQualified(type, name, loc, subOptions, lookupResults);
387394

test/NameLookup/module_selector.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ extension B: @retroactive main::Equatable {
107107
// expected-error@-2 {{cannot infer contextual base in reference to member 'main::min'}}
108108

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

112114
self.main::myNegate()
@@ -140,6 +142,8 @@ extension C: @retroactive ModuleSelectorTestingKit::Equatable {
140142
@_dynamicReplacement(for: ModuleSelectorTestingKit::negate())
141143

142144
mutating func myNegate() {
145+
// FIXME improve: expected-note@-1 {{did you mean 'myNegate'?}}
146+
143147
let fn: (ModuleSelectorTestingKit::Int, ModuleSelectorTestingKit::Int) -> ModuleSelectorTestingKit::Int =
144148
// FIXME improve: expected-error@-1 3{{cannot find type 'ModuleSelectorTestingKit::Int' in scope}}
145149
(ModuleSelectorTestingKit::+)
@@ -157,11 +161,13 @@ extension C: @retroactive ModuleSelectorTestingKit::Equatable {
157161
}
158162
else {
159163
self = ModuleSelectorTestingKit::C(value: .ModuleSelectorTestingKit::min)
164+
// FIXME improve: expected-error@-1 {{type 'Int' has no member 'ModuleSelectorTestingKit::min'}}
160165

161166
self = C.ModuleSelectorTestingKit::init(value: .min)
162167
}
163168

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

166172
ModuleSelectorTestingKit::fatalError()
167173
// FIXME improve: expected-error@-1 {{cannot find 'ModuleSelectorTestingKit::fatalError' in scope}}
@@ -212,9 +218,12 @@ extension D: @retroactive Swift::Equatable {
212218
// expected-error@-2 {{cannot infer contextual base in reference to member 'Swift::min'}}
213219

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

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

219228
Swift::fatalError()
220229
}
@@ -293,6 +302,8 @@ func badModuleNames() {
293302
// expected-error@-1 {{cannot find 'NonexistentModule::print' in scope}}
294303

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

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

0 commit comments

Comments
 (0)