@@ -219,7 +219,12 @@ private struct SourceFile {
219
219
)
220
220
}
221
221
222
- func position( of location: borrowing some AnySourceLocation ) -> AbsolutePosition {
222
+ func position( of location: borrowing some AnySourceLocation ) throws -> AbsolutePosition {
223
+ guard try AbsolutePath ( validating: location. filename) == self . path else {
224
+ // Wrong source file.
225
+ throw Error . failedToResolveSourceLocation
226
+ }
227
+
223
228
guard location. offset == 0 else {
224
229
return AbsolutePosition ( utf8Offset: Int ( location. offset) )
225
230
}
@@ -231,7 +236,7 @@ private struct SourceFile {
231
236
}
232
237
233
238
func node( at location: some AnySourceLocation ) throws -> Syntax {
234
- let position = position ( of: location)
239
+ let position = try position ( of: location)
235
240
236
241
if let token = syntax. token ( at: position) {
237
242
return SwiftSyntax . Syntax ( token)
@@ -305,10 +310,10 @@ extension DiagnosticConverter {
305
310
private static func fixIt(
306
311
from diagnostic: borrowing some AnyDiagnostic ,
307
312
in sourceFile: borrowing SourceFile
308
- ) -> SwiftDiagnostics . FixIt {
309
- let changes = diagnostic. fixIts. map { fixIt in
310
- let startPosition = sourceFile. position ( of: fixIt. start)
311
- let endPosition = sourceFile. position ( of: fixIt. end)
313
+ ) throws -> SwiftDiagnostics . FixIt {
314
+ let changes = try diagnostic. fixIts. map { fixIt in
315
+ let startPosition = try sourceFile. position ( of: fixIt. start)
316
+ let endPosition = try sourceFile. position ( of: fixIt. end)
312
317
313
318
return SwiftDiagnostics . FixIt. Change. replaceText (
314
319
range: startPosition ..< endPosition,
@@ -325,8 +330,8 @@ extension DiagnosticConverter {
325
330
in sourceFile: borrowing SourceFile
326
331
) throws -> [ Syntax ] {
327
332
try diagnostic. ranges. map { startLocation, endLocation in
328
- let startPosition = sourceFile. position ( of: startLocation)
329
- let endPosition = sourceFile. position ( of: endLocation)
333
+ let startPosition = try sourceFile. position ( of: startLocation)
334
+ let endPosition = try sourceFile. position ( of: endLocation)
330
335
331
336
var highlightedNode = try sourceFile. node ( at: startLocation)
332
337
0 commit comments