File tree 1 file changed +16
-3
lines changed
compiler/src/dotty/tools/dotc/core
1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -1770,6 +1770,9 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
1770
1770
totalCount = 0
1771
1771
}
1772
1772
}
1773
+
1774
+ /** Returns last check's debug mode, if explicitly enabled. */
1775
+ def lastTrace (): String = " "
1773
1776
}
1774
1777
1775
1778
object TypeComparer {
@@ -1801,11 +1804,21 @@ object TypeComparer {
1801
1804
1802
1805
val NoApprox : ApproxState = new ApproxState (0 )
1803
1806
1807
+ def explain [T ](say : String => Unit )(op : Context => T )(implicit ctx : Context ): T = {
1808
+ val (res, explanation) = underlyingExplained(op)
1809
+ say(explanation)
1810
+ res
1811
+ }
1812
+
1804
1813
/** Show trace of comparison operations when performing `op` as result string */
1805
1814
def explained [T ](op : Context => T )(implicit ctx : Context ): String = {
1815
+ underlyingExplained(op)._2
1816
+ }
1817
+
1818
+ private def underlyingExplained [T ](op : Context => T )(implicit ctx : Context ): (T , String ) = {
1806
1819
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer (_))
1807
- op(nestedCtx)
1808
- nestedCtx.typeComparer.toString
1820
+ val res = op(nestedCtx)
1821
+ (res, nestedCtx.typeComparer.lastTrace())
1809
1822
}
1810
1823
}
1811
1824
@@ -1937,5 +1950,5 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
1937
1950
1938
1951
override def copyIn (ctx : Context ): ExplainingTypeComparer = new ExplainingTypeComparer (ctx)
1939
1952
1940
- override def toString : String = " Subtype trace:" + { try b.toString finally b.clear() }
1953
+ override def lastTrace () : String = " Subtype trace:" + { try b.toString finally b.clear() }
1941
1954
}
You can’t perform that action at this time.
0 commit comments