@@ -301,12 +301,26 @@ import SwiftSyntax
301301}
302302
303303@_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+ /// ```
304315 @_spi ( Experimental) public func introducesToSequentialParent(
305316 for identifier: Identifier ? ,
306317 at origin: SyntaxProtocol ,
307318 with config: LookupConfig ,
308319 state: LookupState
309320 ) -> [ LookupResult ] {
321+ guard body. position > origin. position || body. endPosition < origin. position
322+ else { return [ ] }
323+
310324 let names = conditions. flatMap { element in
311325 LookupName . getNames ( from: element. condition, accessibleAfter: element. endPosition)
312326 } . filter { introducedName in
@@ -319,32 +333,6 @@ import SwiftSyntax
319333 @_spi ( Experimental) public var introducedNames : [ LookupName ] {
320334 [ ]
321335 }
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- }
348336}
349337
350338@_spi ( Experimental) extension ActorDeclSyntax : TypeScopeSyntax { }
0 commit comments