File tree 2 files changed +43
-5
lines changed
compiler/src/dotty/tools/dotc/transform
tests/neg-custom-args/isInstanceOf 2 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -79,12 +79,11 @@ object TypeTestsCasts {
79
79
80
80
/** Approximate type parameters depending on variance */
81
81
def stripTypeParam (tp : Type )(using Context ) = new ApproximatingTypeMap {
82
- val boundTypeParams = util.HashMap [TypeRef , TypeVar ]()
83
82
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 )
88
87
case _ =>
89
88
mapOver(tp)
90
89
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments