Skip to content

Commit

Permalink
Avoid diagnostic message forcing crashing the compiler (scala#19113)
Browse files Browse the repository at this point in the history
Using issue scala#18650 as the reference (but issue scala#18999 is another option)
building on the fix in PR scala#18719 (refined in PR scala#18727) as well as the
fix in PR scala#18760, I'm trying to make a more root change here by making
sure that message forcing only occurs with `hasErrors`/`errorsReported`
is true, so as to avoid assertion errors crashing the compiler.
  • Loading branch information
odersky authored Dec 17, 2023
2 parents 1f7aa24 + 31165f2 commit 10f2c10
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 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,8 +13,8 @@ trait HideNonSensicalMessages extends Reporter {
*/
override def isHidden(dia: Diagnostic)(using Context): Boolean =
super.isHidden(dia) || {
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
}
}
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
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 10f2c10

Please sign in to comment.