@@ -10,7 +10,7 @@ import java.util.Stack
1010import org.jetbrains.kotlin.ir.IrElement
1111
1212class LogCounter () {
13- public val diagnosticCounts = mutableMapOf<String , Int >()
13+ public val diagnosticInfo = mutableMapOf<String , Pair < Severity , Int > >()
1414 public val diagnosticLimit: Int
1515 init {
1616 diagnosticLimit = System .getenv(" CODEQL_EXTRACTOR_KOTLIN_DIAGNOSTIC_LIMIT" )?.toIntOrNull() ? : 100
@@ -114,12 +114,23 @@ open class LoggerBase(val logCounter: LogCounter) {
114114 if (diagnosticLoc == null ) {
115115 " Missing caller information.\n "
116116 } 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
119130 when {
120131 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
123134 else -> " "
124135 }
125136 }
@@ -189,14 +200,16 @@ open class LoggerBase(val logCounter: LogCounter) {
189200 }
190201
191202 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
193206 if (count >= logCounter.diagnosticLimit) {
194207 // We don't know if this location relates to an error
195208 // or a warning, so we just declare hitting the limit
196209 // to be an error regardless.
197210 val message = " Total of $count diagnostics (reached limit of ${logCounter.diagnosticLimit} ) from $caller ."
198211 if (verbosity >= 1 ) {
199- emitDiagnostic(tw, Severity . Error , " Limit" , message, message)
212+ emitDiagnostic(tw, severity , " Limit" , message, message)
200213 }
201214 }
202215 }
0 commit comments