Skip to content

Commit ff34bf9

Browse files
Fix exhaustivity warning (#16168)
2 parents 275cfa8 + 62de326 commit ff34bf9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ object TypeOps:
875875
}
876876

877877
def instantiate(): Type = {
878+
// if there's a change in variance in type parameters (between subtype tp1 and supertype tp2)
879+
// then we don't want to maximise the type variables in the wrong direction.
880+
// For instance 15967, A[-Z] and B[Y] extends A[Y], we don't want to maximise Y to Any
881+
maximizeType(protoTp1.baseType(tp2.classSymbol), NoSpan)
878882
maximizeType(protoTp1, NoSpan)
879883
wildApprox(protoTp1)
880884
}

tests/pos/i15967.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// scalac: -Werror
2+
sealed trait A[-Z]
3+
final case class B[Y]() extends A[Y]
4+
5+
class Test:
6+
def t1[X](a: A[X]) = a match // was inexhaustive
7+
case _: B[X] @unchecked =>
8+
9+
//def t2[X](a: A[X]) = a match // was inexhaustive
10+
// case _: B[X] => // expected unchecked warning

0 commit comments

Comments
 (0)