Skip to content

Commit 4520faa

Browse files
committed
Instantiate for invariance in paramInstances
1 parent 4f1431d commit 4520faa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3095,7 +3095,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
30953095
def paramInstances(canApprox: Boolean) = new TypeAccumulator[Array[Type]]:
30963096
def apply(insts: Array[Type], t: Type) = t match
30973097
case param @ TypeParamRef(b, n) if b eq caseLambda =>
3098-
def range1(tp: Type) = Range(tp, tp)
3098+
def range1(tp: Type) = if variance == 0 then tp else Range(tp, tp)
30993099
insts(n) =
31003100
if canApprox then
31013101
approximation(param, fromBelow = variance >= 0, Int.MaxValue).simplified

tests/neg/i17149.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type Ext1[S] = S match {
2+
case Seq[t] => t
3+
}
4+
type Ext2[S] = S match {
5+
case Seq[_] => Int
6+
}
7+
type Ext3[S] = S match {
8+
case Array[t] => t
9+
}
10+
type Ext4[S] = S match {
11+
case Array[_] => Int
12+
}
13+
def foo[T <: Seq[Any], A <: Array[B], B] =
14+
summon[Ext1[T] =:= T] // error
15+
summon[Ext2[T] =:= Int] // ok
16+
summon[Ext3[A] =:= B] // ok
17+
summon[Ext4[A] =:= Int] // ok
18+

0 commit comments

Comments
 (0)