Skip to content

Commit

Permalink
Move faking errors to HideNonSensicalMessages
Browse files Browse the repository at this point in the history
Because HideNonSensicalMessages looks at hasErrors, we need to narrow
the faking to just the isNonSensical call
  • Loading branch information
dwijnand committed Nov 30, 2023
1 parent 6875465 commit 4fb8e7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ trait HideNonSensicalMessages extends Reporter {
*/
override def isHidden(dia: Diagnostic)(using Context): Boolean =
super.isHidden(dia) || {
dia.msg.isNonSensical &&
(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
}
Expand Down
19 changes: 3 additions & 16 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 @@ -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 {
Expand Down

0 comments on commit 4fb8e7c

Please sign in to comment.