Search code examples
scalasingletonpattern-matchingscala-2.10non-exhaustive-patterns

Why does Scala 2.10 give 'match may not be exhaustive' warning when matching on singleton types?


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.)


Solution

  • And it's been patched, c.f. https://github.com/retronym/scala/compare/ticket/5968.