Skip to content

Commit 8d60973

Browse files
committed
Show unsuccessful subCapture tests in TypeMismatch explanations
1 parent aeffaca commit 8d60973

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3811,6 +3811,11 @@ class ExplainingTypeComparer(initctx: Context, short: Boolean) extends TypeCompa
38113811
private val b = new StringBuilder
38123812
private var lastForwardGoal: String | Null = null
38133813

3814+
private def appendFailure(x: String) =
3815+
if lastForwardGoal != null then // last was deepest goal that failed
3816+
b.append(s" = $x")
3817+
lastForwardGoal = null
3818+
38143819
override def traceIndented[T](str: String)(op: => T): T =
38153820
val str1 = str.replace('\n', ' ')
38163821
if short && str1 == lastForwardGoal then
@@ -3822,12 +3827,13 @@ class ExplainingTypeComparer(initctx: Context, short: Boolean) extends TypeCompa
38223827
b.append("\n").append(" " * indent).append("==> ").append(str1)
38233828
val res = op
38243829
if short then
3825-
if res == false then
3826-
if lastForwardGoal != null then // last was deepest goal that failed
3827-
b.append(" = false")
3828-
lastForwardGoal = null
3829-
else
3830-
b.length = curLength // don't show successful subtraces
3830+
res match
3831+
case false =>
3832+
appendFailure("false")
3833+
case res: CaptureSet.CompareResult if res != CaptureSet.CompareResult.OK =>
3834+
appendFailure(show(res))
3835+
case _ =>
3836+
b.length = curLength // don't show successful subtraces
38313837
else
38323838
b.append("\n").append(" " * indent).append("<== ").append(str1).append(" = ").append(show(res))
38333839
indent -= 2

0 commit comments

Comments
 (0)