Skip to content

Commit 90323d5

Browse files
committed
Remove force unwrapping for source location
Companion of swiftlang/swift-syntax#1532
1 parent 919cf8e commit 90323d5

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

lib/ASTGen/Sources/ASTGen/PluginHost.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ extension PluginMessage.Syntax {
380380
fileID: fileID,
381381
fileName: fileName,
382382
offset: loc.offset,
383-
line: loc.line!,
384-
column: loc.column!))
383+
line: loc.line,
384+
column: loc.column))
385385
}
386386
}

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ public struct FileIDMacro: ExpressionMacro {
3838
of macro: Node,
3939
in context: Context
4040
) throws -> ExprSyntax {
41-
guard let sourceLoc = context.location(of: macro),
42-
let fileID = sourceLoc.file
43-
else {
41+
guard let sourceLoc = context.location(of: macro) else {
4442
throw CustomError.message("can't find location for macro")
4543
}
4644

47-
let fileLiteral: ExprSyntax = "\(literal: fileID)"
45+
let fileLiteral: ExprSyntax = "\(literal: sourceLoc.file)"
4846
return fileLiteral
4947
}
5048
}
@@ -746,7 +744,7 @@ public enum LeftHandOperandFinderMacro: ExpressionMacro {
746744
fatalError("missing source location information")
747745
}
748746

749-
print("Source range for LHS is \(lhsStartLoc.file!): \(lhsStartLoc.line!):\(lhsStartLoc.column!)-\(lhsEndLoc.line!):\(lhsEndLoc.column!)")
747+
print("Source range for LHS is \(lhsStartLoc.file): \(lhsStartLoc.line):\(lhsStartLoc.column)-\(lhsEndLoc.line):\(lhsEndLoc.column)")
750748

751749
return .visitChildren
752750
}

0 commit comments

Comments
 (0)