Open
Description
Compiling the following code:
object opaq {
opaque type Pos = Int
enum E[T] {
case IntLit(i: Int) extends E[Int]
case PosLit(p: Pos) extends E[Pos]
case StrLit(s: String) extends E[String]
}
def eval(e: E[Pos]): Pos = e match {
case E.PosLit(p) => p
}
}
emits a warning like this:
10: Pattern Match Exhaustivity: E.IntLit(_)
and it should emit a warning like this:
10: Pattern Match Exhaustivity: E.StrLit(_), E.IntLit(_)
See discussion starting around #5300 (comment).
To sum up the discussion we had about this, the issue happens because opaque
aliases are revealed during ElimOpaque
phase, which happens before exhaustivity checks. To fix this, their order should be reversed. We should be careful with moving ElimOpaque
further (in particular we should not move it right before erasure), since warnings & optimisations currently after ElimOpaque
may actually want to see through the opaque alias. It may be easier to instead move exhaustivity checks before ElimOpaque
.