Skip to content

Commit d1fa5d7

Browse files
committed
Simplify TypeComparer.explaining
1 parent f75f58f commit d1fa5d7

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,20 +1822,17 @@ object TypeComparer {
18221822

18231823
/** Show trace of comparison operations when performing `op` as result string */
18241824
def explaining[T](say: String => Unit)(op: Context => T)(implicit ctx: Context): T = {
1825-
val (res, explanation) = underlyingExplained(op)
1826-
say(explanation)
1825+
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
1826+
val res = op(nestedCtx)
1827+
say(nestedCtx.typeComparer.lastTrace())
18271828
res
18281829
}
18291830

18301831
/** Like [[explaining]], but returns the trace instead */
18311832
def explained[T](op: Context => T)(implicit ctx: Context): String = {
1832-
underlyingExplained(op)._2
1833-
}
1834-
1835-
private def underlyingExplained[T](op: Context => T)(implicit ctx: Context): (T, String) = {
1836-
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
1837-
val res = op(nestedCtx)
1838-
(res, nestedCtx.typeComparer.lastTrace())
1833+
var trace: String = null
1834+
explaining(trace = _)(op)
1835+
trace
18391836
}
18401837
}
18411838

0 commit comments

Comments
 (0)