Skip to content

Commit 1b8d84d

Browse files
committed
Also print the position of error/warning associated with a note
1 parent aac93ed commit 1b8d84d

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

Sources/SwiftSyntax/Diagnostic.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,11 @@ public struct Diagnostic: Codable, CustomDebugStringConvertible {
170170

171171
public var debugDescription: String {
172172
var lines: [String] = []
173-
if let location = location {
174-
lines.append("\(location) \(message.debugDescription)")
175-
} else {
176-
lines.append("\(message.debugDescription)")
177-
}
173+
let loc = location == nil ? "" : "\(location!) "
174+
lines.append("\(loc)\(message.debugDescription)")
178175
fixIts.forEach { lines.append("\($0.debugDescription)") }
179-
highlights.forEach { lines.append("Hightlight: \($0.debugDescription)") }
180-
lines.append(contentsOf: notes.map({$0.asDiagnostic().debugDescription}))
176+
highlights.forEach { lines.append("Highlight: \($0.debugDescription)") }
177+
lines.append(contentsOf: notes.map({ loc + $0.asDiagnostic().debugDescription}))
181178
return lines.joined(separator: "\n")
182179
}
183180

lit_tests/parser-diags.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let number⁚ Int
88
// CHECK-NEXT: [[@LINE+2]]:3 error: invalid character in source file
99
// CHECK-NEXT: Fixit: ([[@LINE+1]]:3,[[@LINE+1]]:6) Text: " "
1010
55
11-
// CHECK-NEXT: [[@LINE-1]]:3 note: unicode character '‒' looks similar to '-'; did you mean to use '-'?
11+
// CHECK-NEXT: [[@LINE-1]]:3 [[@LINE-1]]:3 note: unicode character '‒' looks similar to '-'; did you mean to use '-'?
1212
// CHECK-NEXT: Fixit: ([[@LINE-2]]:3,[[@LINE-2]]:6) Text: "-"
1313
// CHECK-NEXT: [[@LINE-3]]:2 error: consecutive statements on a line must be separated by ';'
1414
// CHECK-NEXT: Fixit: ([[@LINE-4]]:2,[[@LINE-4]]:2) Text: ";"
@@ -20,7 +20,7 @@ if (true ꝸꝸꝸ false) {}
2020
if (55) == 0 {}
2121
// CHECK-NEXT: [[@LINE-1]]:7 error: invalid character in source file
2222
// CHECK-NEXT: Fixit: ([[@LINE-2]]:7,[[@LINE-2]]:10) Text: " "
23-
// CHECK-NEXT: [[@LINE-3]]:7 note: unicode character '‒' looks similar to '-'; did you mean to use '-'?
23+
// CHECK-NEXT: [[@LINE-3]]:7 [[@LINE-3]]:7 note: unicode character '‒' looks similar to '-'; did you mean to use '-'?
2424
// CHECK-NEXT: Fixit: ([[@LINE-4]]:7,[[@LINE-4]]:10) Text: "-"
2525
// CHECK-NEXT: [[@LINE-5]]:11 error: expected ',' separator
2626
// CHECK-NEXT: Fixit: ([[@LINE-6]]:6,[[@LINE-6]]:6) Text: ","

0 commit comments

Comments
 (0)