Skip to content

Commit c3540bb

Browse files
committed
Provide better info on compiler crashes
When encountering a compiler crash, show the current phase and the currently compiled unit.
1 parent d670018 commit c3540bb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/core/Phases.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ object Phases {
308308
def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
309309
units.map { unit =>
310310
val unitCtx = ctx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports
311-
run(using unitCtx)
311+
try run(using unitCtx)
312+
catch case ex: Throwable =>
313+
println(s"$ex while running $phaseName on $unit")
314+
throw ex
312315
unitCtx.compilationUnit
313316
}
314317

compiler/src/dotty/tools/dotc/typer/TyperPhase.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase {
3838
}
3939

4040
def typeCheck(using Context): Unit = monitor("typechecking") {
41+
val unit = ctx.compilationUnit
4142
try
42-
val unit = ctx.compilationUnit
4343
if !unit.suspended then
4444
unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree)
4545
typr.println("typed: " + unit.source)
@@ -48,6 +48,9 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase {
4848
ctx.run.nn.suppressions.reportSuspendedMessages(unit.source)
4949
catch
5050
case ex: CompilationUnit.SuspendException =>
51+
case ex: Throwable =>
52+
println(s"$ex while typechecking $unit")
53+
throw ex
5154
}
5255

5356
def javaCheck(using Context): Unit = monitor("checking java") {

0 commit comments

Comments
 (0)