Skip to content

Commit f143077

Browse files
authored
Merge pull request #9789 from dotty-staging/fix-9782
2 parents 04659be + 2dcdda2 commit f143077

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import config.Printers.{ transforms => debug }
2727
object TypeTestsCasts {
2828
import ast.tpd._
2929
import typer.Inferencing.maximizeType
30-
import typer.ProtoTypes.constrained
30+
import typer.ProtoTypes.{ constrained, newTypeVar }
3131

3232
/** Whether `(x:X).isInstanceOf[P]` can be checked at runtime?
3333
*
@@ -77,13 +77,12 @@ object TypeTestsCasts {
7777

7878
/** Approximate type parameters depending on variance */
7979
def stripTypeParam(tp: Type)(using Context) = new ApproximatingTypeMap {
80+
val boundTypeParams = util.HashMap[TypeRef, TypeVar]()
8081
def apply(tp: Type): Type = tp match {
8182
case _: MatchType =>
8283
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))
8786
case _ =>
8887
mapOver(tp)
8988
}
@@ -126,6 +125,7 @@ object TypeTestsCasts {
126125
debug.println("P1 <:< P = " + res)
127126

128127
res
128+
129129
}
130130

131131
def recur(X: Type, P: Type): Boolean = (X <:< P) || (P.dealias match {
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

tests/pos/i9782.scala

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)