Skip to content

Commit

Permalink
Call hasErrors first but then bump before doReport
Browse files Browse the repository at this point in the history
We can switch to a more straightforward hasErrors check in isHidden, but
then we need to bump the errorCount before calling doReport, as doReport
will then, necessarily, force the message.

For reference, the way I test this manually is by:
  1. In ignoredConvertibleImplicits, changing back to `viewExists(imp, fail.expectedType)`
  2. In adapt1, removing the `dummyTreeOfType.unapply(tree).isEmpty` guard
  3. Compiling tests/neg/i18650.scala

Also, while I'm here, instruct on the presence of
-Yno-enrich-error-messages, like we do for -Yno-decode-stacktraces.
  • Loading branch information
dwijnand committed Dec 15, 2023
1 parent 4fb8e7c commit 31165f2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ 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,19 +13,8 @@ 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) &&
hasErrors && // if there are no errors yet, report even if diagnostic is non-sensical
!ctx.settings.YshowSuppressedErrors.value
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
}
}
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

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 @@ -155,8 +155,6 @@ 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 @@ -169,6 +167,8 @@ 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 31165f2

Please sign in to comment.