Skip to content

Commit fc870d0

Browse files
committed
Root unqualified lookups with module selectors at file scope
# Conflicts: # lib/AST/ASTScopeLookup.cpp
1 parent bd7491a commit fc870d0

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
274274
DC->getParentSourceFile());
275275

276276
if (Loc.isValid() && DC->getParentSourceFile()) {
277-
// Operator lookup is always global, for the time being.
278-
if (!Name.isOperator())
277+
// Operator lookup is always global, for the time being. Unqualified lookups
278+
// with module selectors always start at global scope.
279+
if (!Name.isOperator() && !Name.hasModuleSelector())
279280
lookInASTScopes();
280281
} else {
281282
assert((DC->isModuleScopeContext() || !DC->getParentSourceFile()) &&

test/NameLookup/module_selector.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %target-typecheck-verify-swift -sdk %clang-importer-sdk -module-name main -I %S/Inputs -enable-experimental-module-selector
22

3+
// FIXME: This only works with ASTScopes, and we might not care about that by the time this feature is ready.
4+
// RUN-DISABLED: %target-typecheck-verify-swift -sdk %clang-importer-sdk -module-name main -I %S/Inputs -enable-experimental-module-selector -disable-astscope-lookup
5+
36
// Make sure the lack of the experimental flag disables the feature:
47
// RUN: not %target-typecheck-verify-swift -sdk %clang-importer-sdk -module-name main -I %S/Inputs 2>/dev/null
58

@@ -72,7 +75,7 @@ extension ModuleSelectorTestingKit::C: ModuleSelectorTestingKit::Equatable {
7275
// FIXME: expected-error@-3 {{variable used within its own initial value}}
7376
if ModuleSelectorTestingKit::Bool.ModuleSelectorTestingKit::random() {
7477
ModuleSelectorTestingKit::negate()
75-
// expected-EVENTUALLY-error@-1 {{something about not finding 'negate' because we didn't look in self}}
78+
// FIXME improve, suggest adding 'self.': expected-error@-1 {{use of unresolved identifier 'ModuleSelectorTestingKit::negate'}}
7679
}
7780
else {
7881
self = ModuleSelectorTestingKit::C(value: .ModuleSelectorTestingKit::min)
@@ -185,61 +188,57 @@ func main::decl1(
185188
) {
186189
let main::decl1a = "a"
187190
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
188-
// expected-warning@-2 {{never used}}
189191

190192
var main::decl1b = "b"
191193
// expected-error@-1 {{name of variable declaration cannot be qualified with module selector}}
192-
// expected-warning@-2 {{never used}}
193194

194195
let (main::decl1c, main::decl1d) = ("c", "d")
195196
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
196197
// expected-error@-2 {{name of constant declaration cannot be qualified with module selector}}
197-
// expected-warning@-3 2{{never used}}
198198

199199
if let (main::decl1e, main::decl1f) = Optional(("e", "f")) {}
200200
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
201201
// expected-error@-2 {{name of constant declaration cannot be qualified with module selector}}
202-
// expected-warning@-3 2{{never used}}
203202

204203
guard let (main::decl1g, main::decl1h) = Optional(("g", "h")) else { return }
205204
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
206205
// expected-error@-2 {{name of constant declaration cannot be qualified with module selector}}
207-
// expected-warning@-3 {{never used}}
208206

209-
switch Optional(main::decl1g) { // FIXME expecting an error later
207+
// From uses in the switch statements below:
208+
// expected-note@-5 3{{did you mean 'decl1g'?}}
209+
210+
switch Optional(main::decl1g) {
211+
// expected-error@-1 {{use of unresolved identifier 'main::decl1g'}}
210212
case Optional.some(let main::decl1i):
211213
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
212-
// expected-warning@-2 {{never used}}
213214
break
214215
case .none:
215216
break
216217
}
217218

218-
switch Optional(main::decl1g) { // FIXME expecting an error later
219+
switch Optional(main::decl1g) {
220+
// expected-error@-1 {{use of unresolved identifier 'main::decl1g'}}
219221
case let Optional.some(main::decl1j):
220222
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
221-
// expected-warning@-2 {{never used}}
222223
break
223224
case .none:
224225
break
225226
}
226227

227228
switch Optional(main::decl1g) {
228-
case let main::decl1k?:
229+
// expected-error@-1 {{use of unresolved identifier 'main::decl1g'}}
230+
case let main::decl1k?:
229231
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
230-
// expected-warning@-2 {{never used}}
231232
break
232233
case .none:
233234
break
234235
}
235236

236237
for main::decl1l in "lll" {}
237238
// expected-error@-1 {{name of constant declaration cannot be qualified with module selector}}
238-
// expected-warning@-2 {{never used}}
239239

240240
"lll".forEach { [main::magnitude]
241241
// expected-error@-1 {{name of captured variable declaration cannot be qualified with module selector}}
242-
// expected-warning@-2 {{never used}}
243242
main::elem in print(elem)
244243
// expected-error@-1 {{name of parameter declaration cannot be qualified with module selector}}
245244
}

0 commit comments

Comments
 (0)