@@ -91,10 +91,18 @@ func emitDiagnostic(
91
91
diagnostic: Diagnostic ,
92
92
messageSuffix: String ? = nil
93
93
) {
94
+ // Determine the set of note IDs.
95
+ let knownNoteIDs : Set < MessageID > = . init(
96
+ diagnostic. notes. map { $0. noteMessage. fixItID }
97
+ )
98
+
94
99
// Collect all of the Fix-It changes based on their Fix-It ID.
95
100
var fixItChangesByID : [ MessageID : [ FixIt . Change ] ] = [ : ]
96
101
for fixIt in diagnostic. fixIts {
97
- fixItChangesByID [ fixIt. message. fixItID, default: [ ] ]
102
+ let id = knownNoteIDs. contains ( fixIt. message. fixItID)
103
+ ? fixIt. message. fixItID
104
+ : diagnostic. diagnosticID
105
+ fixItChangesByID [ id, default: [ ] ]
98
106
. append ( contentsOf: fixIt. changes. changes)
99
107
}
100
108
@@ -109,6 +117,8 @@ func emitDiagnostic(
109
117
fixItChanges: fixItChangesByID [ diagnostic. diagnosticID] ?? [ ]
110
118
)
111
119
120
+ fixItChangesByID. removeValue ( forKey: diagnostic. diagnosticID)
121
+
112
122
// Emit any notes as follow-ons.
113
123
for note in diagnostic. notes {
114
124
emitDiagnosticParts (
@@ -118,5 +128,10 @@ func emitDiagnostic(
118
128
severity: . note, position: note. position,
119
129
fixItChanges: fixItChangesByID [ note. noteMessage. fixItID] ?? [ ]
120
130
)
131
+
132
+ fixItChangesByID. removeValue ( forKey: note. noteMessage. fixItID)
121
133
}
134
+
135
+ // All Fix-Its must have been removed by the code above.
136
+ assert ( fixItChangesByID. isEmpty)
122
137
}
0 commit comments