Code without upper bound on match type compiles without warning
enum A {
case AA
}
enum B {
case BA
case BB
}
type P[X <: A] = X match {
case A.AA.type => B.BA.type
}
def apply[X <: A](x: X, y: P[X]): Unit = x match {
case x: A.AA.type => y match {
case y: B.BA.type => ???
}
}
while the code with upper bound warns “match may not be exhaustive.”:
enum A {
case AA
}
enum B {
case BA
case BB
}
type P[X <: A] <: B = X match { // Upper bound added
case A.AA.type => B.BA.type
}
def apply[X <: A](x: X, y: P[X]): Unit = x match {
case x: A.AA.type => y match {
case y: B.BA.type => ??? // match may not be exhaustive. It would fail on pattern case: BB
}
}