@@ -67,17 +67,17 @@ object Checkable {
67
67
def isAbstract (P : Type ) = ! P .dealias.typeSymbol.isClass
68
68
def isPatternTypeSymbol (sym : Symbol ) = ! sym.isClass && sym.is(Case )
69
69
70
- def replaceP (implicit ctx : Context ) = new TypeMap {
70
+ def replaceP (tp : Type )( implicit ctx : Context ) = new TypeMap {
71
71
def apply (tp : Type ) = tp match {
72
72
case tref : TypeRef
73
73
if isPatternTypeSymbol(tref.typeSymbol) => WildcardType
74
74
case AnnotatedType (_, annot)
75
75
if annot.symbol == defn.UncheckedAnnot => WildcardType
76
76
case _ => mapOver(tp)
77
77
}
78
- }
78
+ }.apply(tp)
79
79
80
- def replaceX (implicit ctx : Context ) = new TypeMap {
80
+ def replaceX (tp : Type )( implicit ctx : Context ) = new TypeMap {
81
81
def apply (tp : Type ) = tp match {
82
82
case tref : TypeRef
83
83
if isPatternTypeSymbol(tref.typeSymbol) =>
@@ -86,18 +86,19 @@ object Checkable {
86
86
else OrType (defn.AnyType , defn.NothingType )
87
87
case _ => mapOver(tp)
88
88
}
89
- }
89
+ }.apply(tp)
90
90
91
- def stripTypeParam (implicit ctx : Context ) = new ApproximatingTypeMap {
91
+ /** Approximate type parameters depending on variance */
92
+ def stripTypeParam (tp : Type )(implicit ctx : Context ) = new ApproximatingTypeMap {
92
93
def apply (tp : Type ): Type = tp match {
93
94
case tp : TypeRef if tp.underlying.isInstanceOf [TypeBounds ] =>
94
- val lo = this (tp.info.loBound)
95
- val hi = this (tp.info.hiBound)
95
+ val lo = apply (tp.info.loBound)
96
+ val hi = apply (tp.info.hiBound)
96
97
range(lo, hi)
97
98
case _ =>
98
99
mapOver(tp)
99
100
}
100
- }
101
+ }.apply(tp)
101
102
102
103
def isClassDetermined (X : Type , P : AppliedType )(implicit ctx : Context ) = {
103
104
val AppliedType (tycon, _) = P
@@ -131,16 +132,17 @@ object Checkable {
131
132
case _ => recur(defn.AnyType , tpT)
132
133
}
133
134
case tpe : AppliedType =>
135
+ // first try withou striping type parameters for performance
134
136
isClassDetermined(X , tpe)(ctx.fresh.setNewTyperState()) ||
135
- isClassDetermined(stripTypeParam.apply (X ), tpe)(ctx.fresh.setNewTyperState())
137
+ isClassDetermined(stripTypeParam(X ), tpe)(ctx.fresh.setNewTyperState())
136
138
case AndType (tp1, tp2) => recur(X , tp1) && recur(X , tp2)
137
139
case OrType (tp1, tp2) => recur(X , tp1) && recur(X , tp2)
138
140
case AnnotatedType (t, _) => recur(X , t)
139
141
case _ : RefinedType => false
140
142
case _ => true
141
143
})
142
144
143
- val res = recur(replaceX.apply (X .widen), replaceP.apply (P ))
145
+ val res = recur(replaceX(X .widen), replaceP(P ))
144
146
145
147
debug.println(i " checking ${X .show} isInstanceOf ${P } = $res" )
146
148
0 commit comments