From 7bfa9e423f8b80a13a16942feb94f8ca9bcb8894 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Dec 2023 10:17:01 +0100 Subject: [PATCH 1/3] Revert "Call hasErrors first but then bump before doReport" This reverts commit 31165f276204404c5a9910d3308e09b71ebf1ca5. --- compiler/src/dotty/tools/dotc/report.scala | 1 - .../reporting/HideNonSensicalMessages.scala | 17 ++++++++++++++--- .../dotty/tools/dotc/reporting/Reporter.scala | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/report.scala b/compiler/src/dotty/tools/dotc/report.scala index 8e39afdd6e7d..00b20b94ac87 100644 --- a/compiler/src/dotty/tools/dotc/report.scala +++ b/compiler/src/dotty/tools/dotc/report.scala @@ -155,7 +155,6 @@ object report: | An unhandled exception was thrown in the compiler. | Please file a crash report here: | https://github.com/lampepfl/dotty/issues/new/choose - | For non-enriched exceptions, compile with -Yno-enrich-error-messages. | |$info1 |""".stripMargin diff --git a/compiler/src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala b/compiler/src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala index 81e17c495d90..50b89d9fb393 100644 --- a/compiler/src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala @@ -13,8 +13,19 @@ trait HideNonSensicalMessages extends Reporter { */ override def isHidden(dia: Diagnostic)(using Context): Boolean = super.isHidden(dia) || { - hasErrors // if there are no errors yet, report even if diagnostic is non-sensical - && dia.msg.isNonSensical // defer forcing the message by calling hasErrors first - && !ctx.settings.YshowSuppressedErrors.value + (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) && + 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 ca4114a82cdc..c24e8ba4f122 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 - private var _errorCount = 0 - private var _warningCount = 0 + protected var _errorCount = 0 + protected var _warningCount = 0 /** The number of errors reported by this reporter (ignoring outer reporters) */ def errorCount: Int = _errorCount @@ -155,6 +155,8 @@ abstract class Reporter extends interfaces.ReporterResult { addUnreported(key, 1) case _ => if !isHidden(dia) then // avoid isHidden test for summarized warnings so that message is not forced + markReported(dia) + withMode(Mode.Printing)(doReport(dia)) dia match { case w: Warning => warnings = w :: warnings @@ -167,8 +169,6 @@ abstract class Reporter extends interfaces.ReporterResult { case _: Info => // nothing to do here // match error if d is something else } - markReported(dia) - withMode(Mode.Printing)(doReport(dia)) end issueUnconfigured def issueIfNotSuppressed(dia: Diagnostic)(using Context): Unit = From f7ae2b72e1f7c6069aab3e9625c93ae0c587cdbf Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Dec 2023 10:17:11 +0100 Subject: [PATCH 2/3] 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 { From 5f42b6aa6cf665d663ee80e602c98d14ace801a1 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Dec 2023 10:17:25 +0100 Subject: [PATCH 3/3] Revert "Set errorsReported while running isHidden and forcing message" This reverts commit 68754650716cd86c5c070dab753f424752e11a1c. --- .../src/dotty/tools/dotc/reporting/Reporter.scala | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala index b3e54d2e6734..f567e094e831 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala @@ -154,20 +154,7 @@ abstract class Reporter extends interfaces.ReporterResult { val key = w.enablingOption.name addUnreported(key, 1) case _ => - 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 + if !isHidden(dia) then // avoid isHidden test for summarized warnings so that message is not forced markReported(dia) withMode(Mode.Printing)(doReport(dia)) dia match {