@@ -10,7 +10,7 @@ import java.util.Stack
10
10
import org.jetbrains.kotlin.ir.IrElement
11
11
12
12
class LogCounter () {
13
- public val diagnosticCounts = mutableMapOf<String , Int >()
13
+ public val diagnosticInfo = mutableMapOf<String , Pair < Severity , Int > >()
14
14
public val diagnosticLimit: Int
15
15
init {
16
16
diagnosticLimit = System .getenv(" CODEQL_EXTRACTOR_KOTLIN_DIAGNOSTIC_LIMIT" )?.toIntOrNull() ? : 100
@@ -114,12 +114,23 @@ open class LoggerBase(val logCounter: LogCounter) {
114
114
if (diagnosticLoc == null ) {
115
115
" Missing caller information.\n "
116
116
} else {
117
- val count = logCounter.diagnosticCounts.getOrDefault(diagnosticLoc, 0 ) + 1
118
- logCounter.diagnosticCounts[diagnosticLoc] = count
117
+ val oldInfo = logCounter.diagnosticInfo.getOrDefault(diagnosticLoc, Pair (severity, 0 ))
118
+ if (severity != oldInfo.first) {
119
+ // We don't want to get in a loop, so just emit this
120
+ // directly without going through the diagnostic
121
+ // counting machinery
122
+ if (verbosity >= 1 ) {
123
+ val message = " Severity mismatch ($severity vs ${oldInfo.first} ) at $diagnosticLoc "
124
+ emitDiagnostic(tw, Severity .Error , " Inconsistency" , message, message)
125
+ }
126
+ }
127
+ val newCount = oldInfo.second + 1
128
+ val newInfo = Pair (severity, newCount)
129
+ logCounter.diagnosticInfo[diagnosticLoc] = newInfo
119
130
when {
120
131
logCounter.diagnosticLimit <= 0 -> " "
121
- count == logCounter.diagnosticLimit -> " Limit reached for diagnostics from $diagnosticLoc .\n "
122
- count > logCounter.diagnosticLimit -> return
132
+ newCount == logCounter.diagnosticLimit -> " Limit reached for diagnostics from $diagnosticLoc .\n "
133
+ newCount > logCounter.diagnosticLimit -> return
123
134
else -> " "
124
135
}
125
136
}
@@ -189,14 +200,16 @@ open class LoggerBase(val logCounter: LogCounter) {
189
200
}
190
201
191
202
fun printLimitedDiagnosticCounts (tw : TrapWriter ) {
192
- for ((caller, count) in logCounter.diagnosticCounts) {
203
+ for ((caller, info) in logCounter.diagnosticInfo) {
204
+ val severity = info.first
205
+ val count = info.second
193
206
if (count >= logCounter.diagnosticLimit) {
194
207
// We don't know if this location relates to an error
195
208
// or a warning, so we just declare hitting the limit
196
209
// to be an error regardless.
197
210
val message = " Total of $count diagnostics (reached limit of ${logCounter.diagnosticLimit} ) from $caller ."
198
211
if (verbosity >= 1 ) {
199
- emitDiagnostic(tw, Severity . Error , " Limit" , message, message)
212
+ emitDiagnostic(tw, severity , " Limit" , message, message)
200
213
}
201
214
}
202
215
}
0 commit comments