From 6b8fbba1262cabf884c53e5a8ce8b4e48d3df51e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Dec 2023 10:17:11 +0100 Subject: [PATCH] Revert "Move faking errors to HideNonSensicalMessages" This reverts commit 4fb8e7c9b1844085325876b4c2db7f5a517be691. --- .../reporting/HideNonSensicalMessages.scala | 13 +------------ .../dotty/tools/dotc/reporting/Reporter.scala | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala b/compiler/src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala index 50b89d9fb393..5910d9b4d656 100644 --- a/compiler/src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala @@ -13,18 +13,7 @@ trait HideNonSensicalMessages extends Reporter { */ override def isHidden(dia: Diagnostic)(using Context): Boolean = super.isHidden(dia) || { - (if !errorsReported && dia.isInstanceOf[Diagnostic.Error] then - // Bump up errorCount so hasErrors is true while forcing the message. - // We use errorsReported as a predicate for broken code. - // So now any forcing won't cause, for instance, - // assertion errors and thus compiler crashes. - // Some messages, once forced, run more code - // to generate useful hints for the user. - try - _errorCount += 1 - dia.msg.isNonSensical - finally _errorCount -= 1 // decrease rather than reset the value so we only ever decrease by 1 - else dia.msg.isNonSensical) && + dia.msg.isNonSensical && hasErrors && // if there are no errors yet, report even if diagnostic is non-sensical !ctx.settings.YshowSuppressedErrors.value } diff --git a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala index c24e8ba4f122..b3e54d2e6734 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala @@ -92,8 +92,8 @@ abstract class Reporter extends interfaces.ReporterResult { private def isIncompleteChecking = incompleteHandler ne defaultIncompleteHandler - protected var _errorCount = 0 - protected var _warningCount = 0 + private var _errorCount = 0 + private var _warningCount = 0 /** The number of errors reported by this reporter (ignoring outer reporters) */ def errorCount: Int = _errorCount @@ -154,7 +154,20 @@ abstract class Reporter extends interfaces.ReporterResult { val key = w.enablingOption.name addUnreported(key, 1) case _ => - if !isHidden(dia) then // avoid isHidden test for summarized warnings so that message is not forced + val hide = if !errorsReported && dia.isInstanceOf[Error] then + // We bump up errorCount so errorsReported is true while executing isHidden. + // We use errorsReported as a predicate for broken code. + // So now any code `isHidden` runs won't cause, for instance, + // assertion errors and thus compiler crashes. + // This normally amounts to forcing the message, which might run more code + // to generate useful hints for the user. + try + _errorCount += 1 + isHidden(dia) + finally + _errorCount -= 1 // decrease rather than set back to `oldErrorCount` so we only ever decrease by 1 + else isHidden(dia) + if !hide then // avoid isHidden test for summarized warnings so that message is not forced markReported(dia) withMode(Mode.Printing)(doReport(dia)) dia match {