diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala index 3b382da58aca..22170a4783f7 100644 --- a/src/dotty/tools/dotc/Driver.scala +++ b/src/dotty/tools/dotc/Driver.scala @@ -50,8 +50,13 @@ abstract class Driver extends DotClass { process(args, initCtx) } - def main(args: Array[String]): Unit = + def main(args: Array[String]): Unit = { + // Preload scala.util.control.NonFatal. Otherwise, when trying to catch a StackOverflowError, + // we may try to load it but fail with another StackOverflowError and lose the original exception, + // see . + val _ = NonFatal sys.exit(if (process(args).hasErrors) 1 else 0) + } } class FatalError(msg: String) extends Exception diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala index 4a72c2066656..5cad0a0770bc 100644 --- a/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/src/dotty/tools/dotc/reporting/Reporter.scala @@ -152,7 +152,12 @@ trait Reporting { this: Context => case _ => String.valueOf(res) } if (printer eq config.Printers.noPrinter) op - else traceIndented[T](s"==> $question?", (res: Any) => s"<== $question = ${resStr(res)}")(op) + else { + // Avoid evaluating question multiple time, since each evaluation + // may cause some extra logging output. + val q: String = question + traceIndented[T](s"==> $q?", (res: Any) => s"<== $q = ${resStr(res)}")(op) + } } def traceIndented[T](leading: => String, trailing: Any => String)(op: => T): T =