Skip to content

Commit b7f6338

Browse files
committed
Fix for newly optional return type of withDigits.
The `withDigits` method was updated to return an optional, which causes this to fail to build. I think a nil value here would indicate an error in swift-format's numeric grouping that resulted in an invalid numeric literal. `withDigits` was udpated in a recent swift-syntax change: swiftlang@94fc5ae#diff-8c79a56bd4eb3d1313169ca412f5e11eL2387
1 parent d4bba6e commit b7f6338

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Sources/SwiftFormatRules/GroupNumericLiterals.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ public final class GroupNumericLiterals: SyntaxFormatRule {
5959
}
6060

6161
newDigits = isNegative ? "-" + newDigits : newDigits
62-
let result = node.withDigits(
63-
SyntaxFactory.makeIntegerLiteral(
64-
newDigits,
65-
leadingTrivia: node.digits.leadingTrivia,
66-
trailingTrivia: node.digits.trailingTrivia))
62+
guard
63+
let result = node.withDigits(
64+
SyntaxFactory.makeIntegerLiteral(
65+
newDigits,
66+
leadingTrivia: node.digits.leadingTrivia,
67+
trailingTrivia: node.digits.trailingTrivia))
68+
else {
69+
return ExprSyntax(node)
70+
}
6771
return ExprSyntax(result)
6872
}
6973

0 commit comments

Comments
 (0)