Skip to content

Commit 099e5a6

Browse files
committed
More explanations for -Ycheck failures.
In case of "types differ" failure, explain why original and retyped type are not subtypes of each other.
1 parent cfd13f7 commit 099e5a6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,19 @@ class TreeChecker {
4848
def sameType(tp1: Type, tp2: Type) =
4949
(tp1 eq tp2) || // accept NoType / NoType
5050
(tp1 =:= tp2)
51-
def divergenceMsg =
51+
def divergenceMsg = {
52+
def explanation(tp1: Type, tp2: Type) =
53+
if (tp1 <:< tp2) ""
54+
else "\n why different:\n" + core.TypeComparer.explained((tp1 <:< tp2)(_))
5255
s"""Types differ
5356
|Original type : ${tree.typeOpt.show}
5457
|After checking: ${tree1.tpe.show}
5558
|Original tree : ${tree.show}
5659
|After checking: ${tree1.show}
57-
""".stripMargin
60+
""".stripMargin +
61+
explanation(tree1.tpe, tree.typeOpt) +
62+
explanation(tree.typeOpt, tree1.tpe)
63+
}
5864
assert(sameType(tree1.tpe, tree.typeOpt), divergenceMsg)
5965
tree1
6066
}

0 commit comments

Comments
 (0)