Skip to content

Commit c2741e4

Browse files
committed
Simplify token(at:) implementation slightly
1 parent 551ffd4 commit c2741e4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Sources/SwiftSyntax/Syntax.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,13 @@ public extension SyntaxProtocol {
406406
}
407407

408408
// Otherwise, it must be one of our children.
409-
return children(viewMode: .sourceAccurate).lazy.compactMap { child in
410-
child.token(at: position)
411-
}.first
409+
for child in children(viewMode: .sourceAccurate) {
410+
if let token = child.token(at: position) {
411+
return token
412+
}
413+
}
414+
415+
fatalError("Children of syntax node do not cover all positions in it")
412416
}
413417

414418
/// The absolute position of the starting point of this node. If the first token

0 commit comments

Comments
 (0)