Skip to content

Commit

Permalink
Revert "Move faking errors to HideNonSensicalMessages"
Browse files Browse the repository at this point in the history
This reverts commit 4fb8e7c.
  • Loading branch information
nicolasstucki committed Dec 18, 2023
1 parent 305c9f3 commit 6b8fbba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 16 additions & 3 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

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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6b8fbba

Please sign in to comment.