File tree 3 files changed +39
-5
lines changed
compiler/src/dotty/tools/dotc/transform
3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ import config.Printers.{ transforms => debug }
27
27
object TypeTestsCasts {
28
28
import ast .tpd ._
29
29
import typer .Inferencing .maximizeType
30
- import typer .ProtoTypes .constrained
30
+ import typer .ProtoTypes .{ constrained , newTypeVar }
31
31
32
32
/** Whether `(x:X).isInstanceOf[P]` can be checked at runtime?
33
33
*
@@ -77,13 +77,12 @@ object TypeTestsCasts {
77
77
78
78
/** Approximate type parameters depending on variance */
79
79
def stripTypeParam (tp : Type )(using Context ) = new ApproximatingTypeMap {
80
+ val boundTypeParams = util.HashMap [TypeRef , TypeVar ]()
80
81
def apply (tp : Type ): Type = tp match {
81
82
case _ : MatchType =>
82
83
tp // break cycles
83
- case tp : TypeRef if isBounds(tp.underlying) =>
84
- val lo = apply(tp.info.loBound)
85
- val hi = apply(tp.info.hiBound)
86
- range(lo, hi)
84
+ case tp : TypeRef if ! tp.symbol.isClass =>
85
+ boundTypeParams.getOrElseUpdate(tp, newTypeVar(tp.underlying.toBounds))
87
86
case _ =>
88
87
mapOver(tp)
89
88
}
@@ -126,6 +125,7 @@ object TypeTestsCasts {
126
125
debug.println(" P1 <:< P = " + res)
127
126
128
127
res
128
+
129
129
}
130
130
131
131
def recur (X : Type , P : Type ): Boolean = (X <:< P ) || (P .dealias match {
Original file line number Diff line number Diff line change
1
+ trait Txn [T <: Txn [T ]]
2
+
3
+ trait Elem [T <: Txn [T ]]
4
+
5
+ trait Obj [T <: Txn [T ]] extends Elem [T ]
6
+
7
+ class Test {
8
+
9
+ def apply [Repr [~ <: Txn [~ ]] <: Elem [~ ], In <: Txn [In ]](in : Repr [In ]): Unit = {
10
+ in match {
11
+ case inObj : Obj [In ] => // problem here
12
+ case _ =>
13
+ }
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ trait Txn [T <: Txn [T ]]
2
+
3
+ trait Elem [T <: Txn [T ]]
4
+
5
+ trait Obj [T <: Txn [T ]] extends Elem [T ]
6
+
7
+ trait Copy [In <: Txn [In ], Out <: Txn [Out ]] {
8
+ def copyImpl [Repr [~ <: Txn [~ ]] <: Elem [~ ]](in : Repr [In ]): Repr [Out ]
9
+
10
+ def apply [Repr [~ <: Txn [~ ]] <: Elem [~ ]](in : Repr [In ]): Repr [Out ] = {
11
+ val out = copyImpl[Repr ](in)
12
+ (in, out) match {
13
+ case (inObj : Obj [In ], outObj : Obj [Out ]) => // problem here
14
+ println(" copy the attributes" )
15
+ case _ =>
16
+ }
17
+ out
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments