@@ -301,12 +301,26 @@ import SwiftSyntax
301
301
}
302
302
303
303
@_spi ( Experimental) extension GuardStmtSyntax : IntroducingToSequentialParentScopeSyntax {
304
+ /// Returns names matching lookup.
305
+ /// Lookup triggered from inside of `else`
306
+ /// returns no names.
307
+ ///
308
+ /// Example:
309
+ /// ```swift
310
+ /// guard let a = x else {
311
+ /// return // a is not visible here
312
+ /// }
313
+ /// // a is visible here
314
+ /// ```
304
315
@_spi ( Experimental) public func introducesToSequentialParent(
305
316
for identifier: Identifier ? ,
306
317
at origin: SyntaxProtocol ,
307
318
with config: LookupConfig ,
308
319
state: LookupState
309
320
) -> [ LookupResult ] {
321
+ guard body. position > origin. position || body. endPosition < origin. position
322
+ else { return [ ] }
323
+
310
324
let names = conditions. flatMap { element in
311
325
LookupName . getNames ( from: element. condition, accessibleAfter: element. endPosition)
312
326
} . filter { introducedName in
@@ -319,32 +333,6 @@ import SwiftSyntax
319
333
@_spi ( Experimental) public var introducedNames : [ LookupName ] {
320
334
[ ]
321
335
}
322
-
323
- /// Returns names matching lookup.
324
- /// Lookup triggered from inside of `else`
325
- /// clause is immediately forwarded to parent scope.
326
- ///
327
- /// Example:
328
- /// ```swift
329
- /// guard let a = x else {
330
- /// return // a is not visible here
331
- /// }
332
- /// // a is visible here
333
- /// ```
334
- @_spi ( Experimental) public func _lookup(
335
- for identifier: Identifier ? ,
336
- at origin: SyntaxProtocol ,
337
- with config: LookupConfig ,
338
- state: LookupState
339
- ) -> [ LookupResult ] {
340
- if body. position <= origin. position && body. endPosition >= origin. position {
341
- var newState = state
342
- newState. skipSequentialIntroductionFrom = self
343
- return lookupInParent ( for: identifier, at: origin, with: config, state: newState)
344
- } else {
345
- return defaultLookupImplementation ( for: identifier, at: origin, with: config, state: state)
346
- }
347
- }
348
336
}
349
337
350
338
@_spi ( Experimental) extension ActorDeclSyntax : TypeScopeSyntax { }
0 commit comments