Skip to content

Commit cd313fb

Browse files
committed
Make error reporting resilient to exception thrown while reporting
Previously the added test failed with `1 error reported` but no actual error message printed, because a stack overflow is thrown while reporting the original error. This is then caught and handled to emit a RecursionOverflow error, but that second error is non-sensical and non-sensical errors are only printed if `hasErrors` returns false. We fix this by deferring incrementing the error count (and therefore having `hasErrors` return true) until after having displayed the error. We also defer calling `markReported` otherwise the second error will also be suppressed. A similar change is necessary in our testing infrastructure to keep the error count is coherent.
1 parent 926e6a3 commit cd313fb

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ 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+
withMode(Mode.Printing)(doReport(dia))
158159
dia match {
159160
case w: Warning =>
160161
warnings = w :: warnings
@@ -168,7 +169,6 @@ abstract class Reporter extends interfaces.ReporterResult {
168169
// match error if d is something else
169170
}
170171
markReported(dia)
171-
withMode(Mode.Printing)(doReport(dia))
172172
end issueUnconfigured
173173

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

compiler/test/dotty/tools/dotc/reporting/TestReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
7171
}
7272

7373
if dia.level >= WARNING then
74-
_diagnosticBuf.append(dia)
7574
_consoleReporter.doReport(dia)
75+
_diagnosticBuf.append(dia)
7676
printMessageAndPos(dia, extra)
7777
}
7878
}

tests/neg/mt-deskolemize.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Expr:
2+
type Value
3+
object Expr:
4+
type Of[V] = Expr { type Value = V }
5+
type ExtractValue[F <: Expr] = F match
6+
case Expr.Of[v] => v
7+
import Expr.ExtractValue
8+
9+
class SimpleLoop1 extends Expr:
10+
type Value = ExtractValue[SimpleLoop2]
11+
12+
class SimpleLoop2 extends Expr:
13+
type Value = ExtractValue[SimpleLoop1]
14+
15+
object Test1:
16+
val x: ExtractValue[SimpleLoop1] = 1 // error

0 commit comments

Comments
 (0)