Skip to content

Commit 8745348

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

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
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+

tests/neg/wildcard-match.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class C
2525

2626
def f[X <: Box[C], Y <: Cov[C], Z <: Contrav[C]] =
2727
def a: BoxElem[X] = ??? // OK
28-
val _: C = a // error
28+
val _: C = a
2929

3030
def a1: CovElem[Y] = ???
3131
val _: C = a1 // error

tests/pos/9890.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ object Test {
4141
)
4242

4343
//compiles fine
44-
//summon[Col[ColFromPos[0], Sudoku1] =:= (x, 8, x, 5, x, x, x, 3, 6)]
44+
summon[Col[ColFromPos[0], Sudoku1] =:= (x, 8, x, 5, x, x, x, 3, 6)]
4545

4646
summon[TupleDedup[(x, 8, x, 5, x, x, x, 3, 6), Nothing] =:= (x, 8, 5, 3, 6)]
4747
//but this doesn't

tests/neg/i15155.scala renamed to tests/pos/i15155.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ type EnumValue[A <: Enumeration] = A match {
77

88
// https://github.com/json4s/json4s/blob/355d8751391773e0d79d04402a4f9fb7bfc684ec/ext/src/main/scala/org/json4s/ext/EnumSerializer.scala#L25-L26
99
class EnumSerializer[E <: Enumeration: ClassTag](enumeration: E) {
10-
val EnumerationClass = classOf[EnumValue[E]] // error
10+
val EnumerationClass = classOf[EnumValue[E]]
1111
}

0 commit comments

Comments
 (0)