Skip to content

Commit 3fc1b1b

Browse files
committed
Root unqualified lookups with module selectors at file scope
1 parent f17207c commit 3fc1b1b

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
249249
}
250250

251251
if (Loc.isValid() && DC->getParentSourceFile()) {
252-
// Operator lookup is always global, for the time being.
253-
if (!Name.isOperator())
252+
// Operator lookup is always global, for the time being. Unqualified lookups
253+
// with module selectors always start at global scope.
254+
if (!Name.isOperator() && !Name.hasModuleSelector())
254255
lookInASTScopes();
255256
} else {
256257
assert((DC->isModuleScopeContext() || !DC->getParentSourceFile()) &&

test/NameLookup/module_selector.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extension ModuleSelectorTestingKit::C: ModuleSelectorTestingKit::Equatable {
7474
// FIXME: expected-error@-3 {{variable used within its own initial value}}
7575
if ModuleSelectorTestingKit::Bool.ModuleSelectorTestingKit::random() {
7676
ModuleSelectorTestingKit::negate()
77-
// expected-EVENTUALLY-error@-1 {{something about not finding 'negate' because we didn't look in self}}
77+
// FIXME improve, suggest adding 'self.': expected-error@-1 {{use of unresolved identifier 'ModuleSelectorTestingKit::negate'}}
7878
}
7979
else {
8080
self = ModuleSelectorTestingKit::C(value: .ModuleSelectorTestingKit::min)
@@ -187,61 +187,57 @@ func main::decl1(
187187
) {
188188
let main::decl1a = "a"
189189
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
190-
// expected-warning@-2 {{never used}}
191190

192191
var main::decl1b = "b"
193192
// expected-error@-1 {{name of variable declaration cannot be qualified with module selector}}
194-
// expected-warning@-2 {{never used}}
195193

196194
let (main::decl1c, main::decl1d) = ("c", "d")
197195
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
198196
// expected-error@-2 {{name of constant declaration cannot be qualified with module selector}}
199-
// expected-warning@-3 2{{never used}}
200197

201198
if let (main::decl1e, main::decl1f) = Optional(("e", "f")) {}
202199
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
203200
// expected-error@-2 {{name of constant declaration cannot be qualified with module selector}}
204-
// expected-warning@-3 2{{never used}}
205201

206202
guard let (main::decl1g, main::decl1h) = Optional(("g", "h")) else { return }
207203
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
208204
// expected-error@-2 {{name of constant declaration cannot be qualified with module selector}}
209-
// expected-warning@-3 {{never used}}
210205

211-
switch Optional(main::decl1g) { // FIXME expecting an error later
206+
// From uses in the switch statements below:
207+
// expected-note@-5 3{{did you mean 'decl1g'?}}
208+
209+
switch Optional(main::decl1g) {
210+
// expected-error@-1 {{use of unresolved identifier 'main::decl1g'}}
212211
case Optional.some(let main::decl1i):
213212
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
214-
// expected-warning@-2 {{never used}}
215213
break
216214
case .none:
217215
break
218216
}
219217

220-
switch Optional(main::decl1g) { // FIXME expecting an error later
218+
switch Optional(main::decl1g) {
219+
// expected-error@-1 {{use of unresolved identifier 'main::decl1g'}}
221220
case let Optional.some(main::decl1j):
222221
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
223-
// expected-warning@-2 {{never used}}
224222
break
225223
case .none:
226224
break
227225
}
228226

229227
switch Optional(main::decl1g) {
230-
case let main::decl1k?:
228+
// expected-error@-1 {{use of unresolved identifier 'main::decl1g'}}
229+
case let main::decl1k?:
231230
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
232-
// expected-warning@-2 {{never used}}
233231
break
234232
case .none:
235233
break
236234
}
237235

238236
for main::decl1l in "lll" {}
239237
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
240-
// expected-warning@-2 {{never used}}
241238

242239
"lll".forEach { [main::magnitude]
243240
// expected-error@-1 {{name of captured variable declaration cannot be qualified with module selector}}
244-
// expected-warning@-2 {{never used}}
245241
main::elem in print(elem)
246242
// expected-error@-1 {{name of parameter declaration cannot be qualified with module selector}}
247243
}

0 commit comments

Comments
 (0)