Skip to content

Commit 65dbc1b

Browse files
committed
More precisely approximating bound type parameter with type variables
1 parent 81da0f6 commit 65dbc1b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import config.Printers.{ transforms => debug }
2626
*/
2727
object TypeTestsCasts {
2828
import ast.tpd._
29-
import typer.Inferencing.maximizeType
30-
import typer.ProtoTypes.constrained
29+
import typer._
30+
import typer.Inferencing._
31+
import typer.ProtoTypes._
3132

3233
/** Whether `(x:X).isInstanceOf[P]` can be checked at runtime?
3334
*
@@ -77,14 +78,12 @@ object TypeTestsCasts {
7778

7879
/** Approximate type parameters depending on variance */
7980
def stripTypeParam(tp: Type)(using Context) = new ApproximatingTypeMap {
81+
val boundTypeParams = util.HashMap[TypeRef, TypeVar]()
8082
def apply(tp: Type): Type = tp match {
8183
case _: MatchType =>
8284
tp // break cycles
8385
case tp: TypeRef if isBounds(tp.underlying) =>
84-
def lo = apply(tp.info.loBound.subst(tp.symbol :: Nil, WildcardType :: Nil))
85-
def hi = apply(tp.info.hiBound.subst(tp.symbol :: Nil, WildcardType :: Nil))
86-
87-
range(lo, hi)
86+
boundTypeParams.getOrElseUpdate(tp, newTypeVar(tp.underlying.toBounds))
8887
case _ =>
8988
mapOver(tp)
9089
}
@@ -127,6 +126,7 @@ object TypeTestsCasts {
127126
debug.println("P1 <:< P = " + res)
128127

129128
res
129+
130130
}
131131

132132
def recur(X: Type, P: Type): Boolean = (X <:< P) || (P.dealias match {

0 commit comments

Comments
 (0)