Closed
Description
The following code (here in Scastie) does not currently work:
sealed abstract class Maybe[A]
final case class Just[A](a: A) extends Maybe[A]
class Empty[A] extends Maybe[A]
object Empty {
def apply[A](): Maybe[A] = new Empty[A]
// def unapply[A](e: Empty[A]): Boolean = true // ok
def unapply[A](e: Empty[A]): true = true
}
object Test {
val a: Maybe[Int] = Just(2)
def main(args: Array[String]): Unit = a match {
case Just(2) => true
case Empty() =>
// ^ Boolean(true) is not a valid result type of an unapply method of an extractor()
}
}
Though it should arguably compile and raise an exhaustivity warning (because it does not match Just(n)
for n != 2
).