@@ -17,6 +17,8 @@ import reporting.trace
17
17
/** Provides methods to compare types.
18
18
*/
19
19
class TypeComparer (initctx : Context ) extends DotClass with ConstraintHandling {
20
+ import TypeComparer .show
21
+
20
22
implicit val ctx = initctx
21
23
22
24
val state = ctx.typerState
@@ -1573,7 +1575,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
1573
1575
1574
1576
/** Show subtype goal that led to an assertion failure */
1575
1577
def showGoal (tp1 : Type , tp2 : Type )(implicit ctx : Context ) = {
1576
- println(i " assertion failure for $tp1 <:< $tp2, frozen = $frozenConstraint" )
1578
+ println(i " assertion failure for ${show( tp1)} <:< ${show( tp2)} , frozen = $frozenConstraint" )
1577
1579
def explainPoly (tp : Type ) = tp match {
1578
1580
case tp : TypeParamRef => ctx.echo(s " TypeParamRef ${tp.show} found in ${tp.binder.show}" )
1579
1581
case tp : TypeRef if tp.symbol.exists => ctx.echo(s " typeref ${tp.show} found in ${tp.symbol.owner.show}" )
@@ -1605,6 +1607,11 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
1605
1607
1606
1608
object TypeComparer {
1607
1609
1610
+ private [core] def show (res : Any )(implicit ctx : Context ) = res match {
1611
+ case res : printing.Showable if ! ctx.settings.YexplainLowlevel .value => res.show
1612
+ case _ => String .valueOf(res)
1613
+ }
1614
+
1608
1615
/** Show trace of comparison operations when performing `op` as result string */
1609
1616
def explained [T ](op : Context => T )(implicit ctx : Context ): String = {
1610
1617
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer (_))
@@ -1615,6 +1622,8 @@ object TypeComparer {
1615
1622
1616
1623
/** A type comparer that can record traces of subtype operations */
1617
1624
class ExplainingTypeComparer (initctx : Context ) extends TypeComparer (initctx) {
1625
+ import TypeComparer .show
1626
+
1618
1627
private [this ] var indent = 0
1619
1628
private val b = new StringBuilder
1620
1629
@@ -1631,11 +1640,6 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
1631
1640
res
1632
1641
}
1633
1642
1634
- private def show (res : Any ) = res match {
1635
- case res : printing.Showable if ! ctx.settings.YexplainLowlevel .value => res.show
1636
- case _ => String .valueOf(res)
1637
- }
1638
-
1639
1643
override def isSubType (tp1 : Type , tp2 : Type ) =
1640
1644
traceIndented(s " ${show(tp1)} <:< ${show(tp2)}${if (Config .verboseExplainSubtype) s " ${tp1.getClass} ${tp2.getClass}" else " " }${if (frozenConstraint) " frozen" else " " }" ) {
1641
1645
super .isSubType(tp1, tp2)
0 commit comments