Skip to content

Commit b559209

Browse files
authored
Merge pull request #12484 from dotty-staging/init-lazy-msg
Compute debug messages lazily in safe init
2 parents b9773d6 + f9d1970 commit b559209

File tree

1 file changed

+6
-5
lines changed
  • compiler/src/dotty/tools/dotc/transform/init

1 file changed

+6
-5
lines changed

compiler/src/dotty/tools/dotc/transform/init/Util.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import config.Printers.Printer
1010
import annotation.tailrec
1111

1212
object Util {
13-
def traceIndented(msg: String, printer: Printer)(using Context): Unit =
13+
def traceIndented(msg: => String, printer: Printer)(using Context): Unit =
1414
printer.println(s"${ctx.base.indentTab * ctx.base.indent} $msg")
1515

16-
def traceOp(msg: String, printer: Printer)(op: => Unit)(using Context): Unit = {
17-
traceIndented(s"==> ${msg}", printer)
16+
def traceOp(msg: => String, printer: Printer)(op: => Unit)(using Context): Unit = {
17+
lazy val computedMsg = msg // Make sure we only compute msg once
18+
traceIndented(s"==> ${computedMsg}", printer)
1819
op
19-
traceIndented(s"<== ${msg}", printer)
20+
traceIndented(s"<== ${computedMsg}", printer)
2021
}
2122

2223
extension (symbol: Symbol) def hasSource(using Context): Boolean =
@@ -38,4 +39,4 @@ object Util {
3839
}
3940
loop(cls.info.baseClasses.dropWhile(sym.owner != _))
4041
}
41-
}
42+
}

0 commit comments

Comments
 (0)