From 95e4631b68a6e2b46ff789d7931a2e7b1e67ab45 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 12 Apr 2021 14:56:21 +0200 Subject: [PATCH] Handle non-local return in trace --- .../src/dotty/tools/dotc/reporting/trace.scala | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/trace.scala b/compiler/src/dotty/tools/dotc/reporting/trace.scala index 07a67c2c9cc2..9036ba1c1dc7 100644 --- a/compiler/src/dotty/tools/dotc/reporting/trace.scala +++ b/compiler/src/dotty/tools/dotc/reporting/trace.scala @@ -74,18 +74,23 @@ trait TraceSyntax: while logctx.reporter.isInstanceOf[StoreReporter] do logctx = logctx.outer def margin = ctx.base.indentTab * ctx.base.indent def doLog(s: String) = if isForced then println(s) else report.log(s) - def finalize(result: Any, note: String) = + def finalize(msg: String) = if !finalized then ctx.base.indent -= 1 - doLog(s"$margin${trailing(result)}$note") + doLog(s"$margin$msg") finalized = true try doLog(s"$margin$leading") ctx.base.indent += 1 val res = op - finalize(res, "") + finalize(trailing(res)) res - catch case ex: Throwable => - finalize("", s" (with exception $ex)") - throw ex + catch + case ex: runtime.NonLocalReturnControl[T] => + finalize(trailing(ex.value)) + throw ex + case ex: Throwable => + val msg = s"<== $q = (with exception $ex)" + finalize(msg) + throw ex end TraceSyntax