Skip to content

Commit 1e59e4f

Browse files
committed
Fix #11178: remove unsound tweak for F-bounds
This reverts #9789. We have made several improvements to F-bounds, the unsound tweak is no longer needed.
1 parent e64d3d1 commit 1e59e4f

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ object TypeTestsCasts {
7979

8080
/** Approximate type parameters depending on variance */
8181
def stripTypeParam(tp: Type)(using Context) = new ApproximatingTypeMap {
82-
val boundTypeParams = util.HashMap[TypeRef, TypeVar]()
8382
def apply(tp: Type): Type = tp match {
84-
case _: MatchType =>
85-
tp // break cycles
86-
case tp: TypeRef if !tp.symbol.isClass =>
87-
boundTypeParams.getOrElseUpdate(tp, newTypeVar(tp.underlying.toBounds))
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)
8887
case _ =>
8988
mapOver(tp)
9089
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
trait Box[+T]
2+
case class Foo[+S](s: S) extends Box[S]
3+
4+
def unwrap2[A](b: Box[A]): A =
5+
b match
6+
case _: Foo[Int] => 0 // error
7+
8+
object Test1 {
9+
// Invariant case, OK
10+
sealed trait Bar[A]
11+
12+
def test[A](bar: Bar[A]) =
13+
bar match {
14+
case _: Bar[Boolean] => ??? // error
15+
case _ => ???
16+
}
17+
}
18+
19+
object Test2 {
20+
// Covariant case
21+
sealed trait Bar[+A]
22+
23+
def test[A](bar: Bar[A]) =
24+
bar match {
25+
case _: Bar[Boolean] => ??? // error
26+
case _ => ???
27+
}
28+
}
29+
30+
object Test3 {
31+
// Contravariant case
32+
sealed trait Bar[-A]
33+
34+
def test[A](bar: Bar[A]) =
35+
bar match {
36+
case _: Bar[Boolean] => ??? // error
37+
case _ => ???
38+
}
39+
}

0 commit comments

Comments
 (0)