Question

In Scala 2.10.0-M4

object X
def f(e: Either[Int, X.type]) = e match {
  case Left(i) => i
  case Right(X) => 0
}

gives:

warning: match may not be exhaustive.
It would fail on the following input: Right(<not X>)

Is this correct? Surely the match is in fact exhaustive.

(Meanwhile, back in Scala 2.9.X we get

error: pattern type is incompatible with expected type;
 found   : object X
 required: X.type
           case Right(X) => 0

which presumably was a bug.)

Was it helpful?

Solution 2

OTHER TIPS

Sadly, there are two values which inhabit X.type. One is the obvious one, X, and the other of course is null. Thus your pattern has missed a case :(

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top