Closed
Description
I'm getting what appears to be a spurious pattern matching exhaustivity warning. I'm trying to define a function Either[X, A] => Int
using pattern matching. My first match clause is for Left(Y)
, where Y
is an object that is a subtype of X
. My second match clause is a wildcard that should catch anything else. But I'm getting a warning that the match would fail for Left(_)
. Note that this compiles with Scala 2.12.7. Relatively minimized case below.
import scala.language.higherKinds
object Test {
trait X
case object Y extends X
trait Foo[F[_], O] {
def bar: Foo[F, O] = this match {
case Qux(fa, f) => qux(fa) {
case Left(Y) => ???
case x => ???
}
}
}
case class Qux[F[_], A, O](fa: F[A], f: Either[X, A] => Int) extends Foo[F, O]
def qux[F[_], A, O](fa: F[A])(f: Either[X, A] => Int): Foo[F, O] =
Qux(fa, f)
}
[error] 11 | case Left(Y) => ???
[error] | ^
[error] | match may not be exhaustive.
[error] |
[error] | It would fail on pattern case: Left(_)
Metadata
Metadata
Assignees
Labels
No labels