From bd079c7a271b4bc8007021b34de6bbacea9fa85f Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Tue, 24 Nov 2015 21:32:50 +0100 Subject: [PATCH 1/2] Avoid repeated unnecessary logging in traceIndented While trying to debug #943 I noticed that the exception output from traceIndented was interspersed with unrelated logging output, this happened because `question` in traceIndented is by-name and was evaluated both before executing an operation and afterwards. --- src/dotty/tools/dotc/reporting/Reporter.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 = From d4e42ea4f886a1a94459d40cfc6faec3ee513fad Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Tue, 24 Nov 2015 21:40:30 +0100 Subject: [PATCH 2/2] Preload scala.util.control.NonFatal --- src/dotty/tools/dotc/Driver.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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