Skip to content

Commit 6bbd310

Browse files
authored
Merge pull request swiftlang#516 from kimdv/kimdv/cherry-pick-remove-computed-location
[5.9] Remove force unwrapping for source location
2 parents bab5ec2 + 6d3bed2 commit 6bbd310

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

Sources/SwiftFormatCore/Finding+Convenience.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,7 @@ import SwiftSyntax
1414

1515
extension Finding.Location {
1616
/// Creates a new `Finding.Location` by converting the given `SourceLocation` from `SwiftSyntax`.
17-
///
18-
/// If the source location is invalid (i.e., any of its fields are nil), then the initializer will
19-
/// return nil.
20-
public init?(_ sourceLocation: SourceLocation) {
21-
guard
22-
let file = sourceLocation.file,
23-
let line = sourceLocation.line,
24-
let column = sourceLocation.column
25-
else {
26-
return nil
27-
}
28-
29-
self.init(file: file, line: line, column: column)
17+
public init(_ sourceLocation: SourceLocation) {
18+
self.init(file: sourceLocation.file, line: sourceLocation.line, column: sourceLocation.column)
3019
}
3120
}

Sources/swift-format/Utilities/UnifiedDiagnosticsEngine.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ final class UnifiedDiagnosticsEngine {
5555
var description: String {
5656
switch self {
5757
case .parserLocation(let location):
58-
// SwiftSyntax's old diagnostic printer also force-unwrapped these, so we assume that they
59-
// will always be present if the location itself is non-nil.
60-
return "\(location.file!):\(location.line!):\(location.column!)"
58+
return "\(location.file):\(location.line):\(location.column)"
6159
case .findingLocation(let location):
6260
return "\(location.file):\(location.line):\(location.column)"
6361
}

0 commit comments

Comments
 (0)