@@ -42,20 +42,20 @@ object Checkable {
42
42
import ProtoTypes ._
43
43
44
44
/** Whether `(x:X).isInstanceOf[P]` can be checked at runtime?
45
+ *
46
+ * Replace `T @unchecked` and pattern binder types (e.g., `_$1`) in P with WildcardType, then check:
45
47
*
46
48
* 1. if `P` is a singleton type, TRUE
47
49
* 2. if `P` is WildcardType, TRUE
48
- * 3. if `P = T @unchecked`, TRUE
49
- * 4. if `P` refers to an abstract type member or type parameter, FALSE
50
- * 5. if `P = Array[T]`, checkable(E, T) where `E` is the element type of `X`, defaults to `Any`.
51
- * 6. if `P` is `pre.F[Ts]` and `pre.F` refers to a class which is not `Array`:
50
+ * 3. if `P` refers to an abstract type member or type parameter, FALSE
51
+ * 4. if `P = Array[T]`, checkable(E, T) where `E` is the element type of `X`, defaults to `Any`.
52
+ * 5. if `P` is `pre.F[Ts]` and `pre.F` refers to a class which is not `Array`:
52
53
* (a) replace `Ts` with fresh type variables `Xs`
53
54
* (b) instantiate `Xs` with the constraint `pre.F[Xs] <:< X`
54
- * (c) `pre.F[Xs] <:< P2`, where `P2` is `P` with pattern binder types (e.g., `_$1`)
55
- * replaced with `WildcardType`.
56
- * 7. if `P = T1 | T2` or `P = T1 & T2`, checkable(X, T1) && checkable(X, T2).
57
- * 8. if `P` is a refinement type, FALSE
58
- * 9. otherwise, TRUE
55
+ * (c) `pre.F[Xs] <:< P`
56
+ * 6. if `P = T1 | T2` or `P = T1 & T2`, checkable(X, T1) && checkable(X, T2).
57
+ * 7. if `P` is a refinement type, FALSE
58
+ * 8. otherwise, TRUE
59
59
*/
60
60
def checkable (X : Type , P : Type )(implicit ctx : Context ): Boolean = {
61
61
def Psym = P .dealias.typeSymbol
@@ -73,23 +73,21 @@ object Checkable {
73
73
}
74
74
75
75
def isClassDetermined (tpe : AppliedType )(implicit ctx : Context ) = {
76
- val AppliedType (tycon, args ) = tpe
76
+ val AppliedType (tycon, _ ) = tpe
77
77
val tvars = tycon.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
78
78
val P1 = tycon.appliedTo(tvars)
79
79
80
80
debug.println(" P1 : " + P1 .show)
81
81
debug.println(" X : " + X .widen)
82
82
83
83
! (P1 <:< X .widen) || {
84
- val P2 = replaceBinderMap.apply(P )
85
- val res = isFullyDefined(P1 , ForceDegree .noBottom) && P1 <:< P2
86
- debug.println(" P2: " + P2 .show)
87
- debug.println(" P1 <:< P2 = " + res)
84
+ val res = isFullyDefined(P1 , ForceDegree .noBottom) && P1 <:< tpe
85
+ debug.println(" P1 <:< P = " + res)
88
86
res
89
87
}
90
88
}
91
89
92
- val res = P match {
90
+ val res = replaceBinderMap.apply( P ) match {
93
91
case _ : SingletonType => true
94
92
case WildcardType => true
95
93
case defn.ArrayOf (tpT) =>
@@ -100,9 +98,9 @@ object Checkable {
100
98
case tpe : AppliedType => ! isAbstract && isClassDetermined(tpe)
101
99
case AndType (tp1, tp2) => checkable(X , tp1) && checkable(X , tp2)
102
100
case OrType (tp1, tp2) => checkable(X , tp1) && checkable(X , tp2)
103
- case AnnotatedType (t, an) => an.symbol == defn. UncheckedAnnot || checkable(X , t)
101
+ case AnnotatedType (t, an) => checkable(X , t)
104
102
case _ : RefinedType => false
105
- case _ => replaceBinderMap.apply( P ) == WildcardType || ! isAbstract
103
+ case _ => ! isAbstract
106
104
}
107
105
108
106
debug.println(i " checking ${X .show} isInstanceOf ${P } = $res" )
0 commit comments