@@ -80,15 +80,25 @@ object TypeTestsCasts {
80
80
debug.println(" P1 : " + P1 .show)
81
81
debug.println(" X : " + X .show)
82
82
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 .
84
84
// It just tries to infer type arguments of P1 from X if the value x
85
85
// conforms to the type skeleton pre.F[_]. Then it goes on to check
86
86
// if P1 <: P, which means the type arguments in P are trivial,
87
87
// thus no runtime checks are needed for them.
88
88
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.
89
100
TypeComparer .constrainPatternType(P1 , X , widenParams = false )
90
101
debug.println(TypeComparer .explained(_.constrainPatternType(P1 , X , widenParams = false )))
91
- true
92
102
}
93
103
94
104
// Maximization of the type means we try to cover all possible values
0 commit comments