diff --git a/compiler/src/dotty/tools/dotc/transform/init/Util.scala b/compiler/src/dotty/tools/dotc/transform/init/Util.scala index 41d77a8fe608..218a873be888 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Util.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Util.scala @@ -10,13 +10,14 @@ import config.Printers.Printer import annotation.tailrec object Util { - def traceIndented(msg: String, printer: Printer)(using Context): Unit = + def traceIndented(msg: => String, printer: Printer)(using Context): Unit = printer.println(s"${ctx.base.indentTab * ctx.base.indent} $msg") - def traceOp(msg: String, printer: Printer)(op: => Unit)(using Context): Unit = { - traceIndented(s"==> ${msg}", printer) + def traceOp(msg: => String, printer: Printer)(op: => Unit)(using Context): Unit = { + lazy val computedMsg = msg // Make sure we only compute msg once + traceIndented(s"==> ${computedMsg}", printer) op - traceIndented(s"<== ${msg}", printer) + traceIndented(s"<== ${computedMsg}", printer) } extension (symbol: Symbol) def hasSource(using Context): Boolean = @@ -38,4 +39,4 @@ object Util { } loop(cls.info.baseClasses.dropWhile(sym.owner != _)) } -} \ No newline at end of file +}