Skip to content

Commit

Permalink
Revert "Call hasErrors first but then bump before doReport"
Browse files Browse the repository at this point in the history
This reverts commit 31165f2.
  • Loading branch information
nicolasstucki committed Dec 18, 2023
1 parent 10f2c10 commit 305c9f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand Down

0 comments on commit 305c9f3

Please sign in to comment.