From b7f63387363411cf80f0e58d713f3e2e31249342 Mon Sep 17 00:00:00 2001 From: Dylan Sturgeon Date: Tue, 6 Oct 2020 16:59:46 -0700 Subject: [PATCH] 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: https://github.com/apple/swift-syntax/commit/94fc5ae3f34fac87380756b9c17ea7c6752a227b#diff-8c79a56bd4eb3d1313169ca412f5e11eL2387 --- .../SwiftFormatRules/GroupNumericLiterals.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/SwiftFormatRules/GroupNumericLiterals.swift b/Sources/SwiftFormatRules/GroupNumericLiterals.swift index fe4b5f7f2..a11af1880 100644 --- a/Sources/SwiftFormatRules/GroupNumericLiterals.swift +++ b/Sources/SwiftFormatRules/GroupNumericLiterals.swift @@ -59,11 +59,15 @@ public final class GroupNumericLiterals: SyntaxFormatRule { } newDigits = isNegative ? "-" + newDigits : newDigits - let result = node.withDigits( - SyntaxFactory.makeIntegerLiteral( - newDigits, - leadingTrivia: node.digits.leadingTrivia, - trailingTrivia: node.digits.trailingTrivia)) + guard + let result = node.withDigits( + SyntaxFactory.makeIntegerLiteral( + newDigits, + leadingTrivia: node.digits.leadingTrivia, + trailingTrivia: node.digits.trailingTrivia)) + else { + return ExprSyntax(node) + } return ExprSyntax(result) }