Skip to content

Commit 10f2c10

Browse files
authored
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.
2 parents 1f7aa24 + 31165f2 commit 10f2c10

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ object report:
155155
| An unhandled exception was thrown in the compiler.
156156
| Please file a crash report here:
157157
| https://github.com/lampepfl/dotty/issues/new/choose
158+
| For non-enriched exceptions, compile with -Yno-enrich-error-messages.
158159
|
159160
|$info1
160161
|""".stripMargin

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

+3-3
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ abstract class Reporter extends interfaces.ReporterResult {
155155
addUnreported(key, 1)
156156
case _ =>
157157
if !isHidden(dia) then // avoid isHidden test for summarized warnings so that message is not forced
158-
markReported(dia)
159-
withMode(Mode.Printing)(doReport(dia))
160158
dia match {
161159
case w: Warning =>
162160
warnings = w :: warnings
@@ -169,6 +167,8 @@ abstract class Reporter extends interfaces.ReporterResult {
169167
case _: Info => // nothing to do here
170168
// match error if d is something else
171169
}
170+
markReported(dia)
171+
withMode(Mode.Printing)(doReport(dia))
172172
end issueUnconfigured
173173

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

0 commit comments

Comments
 (0)