Skip to content

Commit e300188

Browse files
oderskydwijnand
authored andcommitted
Avoid diagnostic message forcing crashing the compiler (scala#19113)
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. (cherry picked from commit 10f2c10)
1 parent 46683d0 commit e300188

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

compiler/src/dotty/tools/dotc/report.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ object report:
158158
| An unhandled exception was thrown in the compiler.
159159
| Please file a crash report here:
160160
| https://github.com/lampepfl/dotty/issues/new/choose
161+
| For non-enriched exceptions, compile with -Yno-enrich-error-messages.
161162
|
162163
|$info1
163164
|""".stripMargin

compiler/src/dotty/tools/dotc/reporting/HideNonSensicalMessages.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ trait HideNonSensicalMessages extends Reporter {
1313
*/
1414
override def isHidden(dia: Diagnostic)(using Context): Boolean =
1515
super.isHidden(dia) || {
16-
dia.msg.isNonSensical &&
17-
hasErrors && // if there are no errors yet, report even if diagnostic is non-sensical
18-
!ctx.settings.YshowSuppressedErrors.value
16+
hasErrors // if there are no errors yet, report even if diagnostic is non-sensical
17+
&& dia.msg.isNonSensical // defer forcing the message by calling hasErrors first
18+
&& !ctx.settings.YshowSuppressedErrors.value
1919
}
2020
}

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ abstract class Reporter extends interfaces.ReporterResult {
154154
case w: Warning if ctx.settings.XfatalWarnings.value => w.toError
155155
case _ => dia
156156
if !isHidden(d) then // avoid isHidden test for summarized warnings so that message is not forced
157-
markReported(d)
158-
withMode(Mode.Printing)(doReport(d))
159157
d match {
160158
case _: Warning => _warningCount += 1
161159
case e: Error =>
@@ -166,6 +164,8 @@ abstract class Reporter extends interfaces.ReporterResult {
166164
case _: Info => // nothing to do here
167165
// match error if d is something else
168166
}
167+
markReported(dia)
168+
withMode(Mode.Printing)(doReport(dia))
169169
end issueUnconfigured
170170

171171
def issueIfNotSuppressed(dia: Diagnostic)(using Context): Unit =

0 commit comments

Comments
 (0)