Skip to content

Commit fdb3540

Browse files
committed
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-value and was evaluated both before executing an operation and afterwards.
1 parent 4463f5e commit fdb3540

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ trait Reporting { this: Context =>
152152
case _ => String.valueOf(res)
153153
}
154154
if (printer eq config.Printers.noPrinter) op
155-
else traceIndented[T](s"==> $question?", (res: Any) => s"<== $question = ${resStr(res)}")(op)
155+
else {
156+
// Avoid evaluating question multiple time, since each evaluation
157+
// may cause some extra logging output.
158+
val q: String = question
159+
traceIndented[T](s"==> $q?", (res: Any) => s"<== $q = ${resStr(res)}")(op)
160+
}
156161
}
157162

158163
def traceIndented[T](leading: => String, trailing: Any => String)(op: => T): T =

0 commit comments

Comments
 (0)