Skip to content

Commit 62dd634

Browse files
committed
Consider -Yexplain-lowlevel when showing goals of failed subtype assertions
1 parent 68eb84e commit 62dd634

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import reporting.trace
1717
/** Provides methods to compare types.
1818
*/
1919
class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
20+
import TypeComparer.show
21+
2022
implicit val ctx = initctx
2123

2224
val state = ctx.typerState
@@ -1573,7 +1575,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
15731575

15741576
/** Show subtype goal that led to an assertion failure */
15751577
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")
15771579
def explainPoly(tp: Type) = tp match {
15781580
case tp: TypeParamRef => ctx.echo(s"TypeParamRef ${tp.show} found in ${tp.binder.show}")
15791581
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 {
16051607

16061608
object TypeComparer {
16071609

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+
16081615
/** Show trace of comparison operations when performing `op` as result string */
16091616
def explained[T](op: Context => T)(implicit ctx: Context): String = {
16101617
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
@@ -1615,6 +1622,8 @@ object TypeComparer {
16151622

16161623
/** A type comparer that can record traces of subtype operations */
16171624
class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
1625+
import TypeComparer.show
1626+
16181627
private[this] var indent = 0
16191628
private val b = new StringBuilder
16201629

@@ -1631,11 +1640,6 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
16311640
res
16321641
}
16331642

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-
16391643
override def isSubType(tp1: Type, tp2: Type) =
16401644
traceIndented(s"${show(tp1)} <:< ${show(tp2)}${if (Config.verboseExplainSubtype) s" ${tp1.getClass} ${tp2.getClass}" else ""}${if (frozenConstraint) " frozen" else ""}") {
16411645
super.isSubType(tp1, tp2)

0 commit comments

Comments
 (0)