Skip to content

Commit 252d3be

Browse files
committed
Simplify lookup from guard ... else handling.
1 parent 059860a commit 252d3be

File tree

3 files changed

+14
-37
lines changed

3 files changed

+14
-37
lines changed

Sources/SwiftLexicalLookup/LookupState.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,5 @@ import Foundation
1515
/// Represents internal state for lookup.
1616
/// It shouldn't be used by clients.
1717
@_spi(Experimental) public struct LookupState {
18-
/// Specifies scopes that introduce names to their parent and
19-
/// should be skipped during lookup in sequential scopes.
20-
var skipSequentialIntroductionFrom: IntroducingToSequentialParentScopeSyntax?
21-
2218
init() {}
2319
}

Sources/SwiftLexicalLookup/ScopeImplementations.swift

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {}

Sources/SwiftLexicalLookup/SequentialScopeSyntax.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ extension SequentialScopeSyntax {
6969
if let introducingToParentScope = Syntax(codeBlockItem.item).asProtocol(SyntaxProtocol.self)
7070
as? IntroducingToSequentialParentScopeSyntax
7171
{
72-
// Check if the enocountered scope should be ignored.
73-
if let scopeToSkip = state.skipSequentialIntroductionFrom,
74-
scopeToSkip.id == introducingToParentScope.id
75-
{
76-
continue
77-
}
78-
7972
// Get results from encountered scope.
8073
let introducedResults = introducingToParentScope.introducesToSequentialParent(
8174
for: identifier,

0 commit comments

Comments
 (0)