Skip to content

Commit aa296ba

Browse files
committed
Add comment for code
1 parent 9b8b812 commit aa296ba

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,25 @@ object TypeTestsCasts {
8080
debug.println("P1 : " + P1.show)
8181
debug.println("X : " + X.show)
8282

83-
// It does not matter if P1 is not a subtype of X.
83+
// It does not matter whether P1 is a subtype of X or not.
8484
// It just tries to infer type arguments of P1 from X if the value x
8585
// conforms to the type skeleton pre.F[_]. Then it goes on to check
8686
// if P1 <: P, which means the type arguments in P are trivial,
8787
// thus no runtime checks are needed for them.
8888
withMode(Mode.GadtConstraintInference) {
89+
// Why not widen type arguments here? Given the following program
90+
//
91+
// trait Tree[-T] class Ident[-T] extends Tree[T] def foo1(tree:
92+
// Tree[Int]) = tree.isInstanceOf[Ident[Int]]
93+
//
94+
// In checking whether the test tree.isInstanceOf[Ident[Int]]
95+
// is realizable, we want to constrain Ident[X] <: Tree[Int],
96+
// such that we can infer X = Int and Ident[X] <:< Ident[Int].
97+
//
98+
// If we perform widening, we will get X = Nothing, and we don't have
99+
// Ident[X] <:< Ident[Int] any more.
89100
TypeComparer.constrainPatternType(P1, X, widenParams = false)
90101
debug.println(TypeComparer.explained(_.constrainPatternType(P1, X, widenParams = false)))
91-
true
92102
}
93103

94104
// Maximization of the type means we try to cover all possible values

0 commit comments

Comments
 (0)