-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complementing irrefutable unapplySeq aren't recognized as exhaustive #12252
Comments
I think it is also the case for regular object NonObj {
def unapply(json: Json): Option[Json] = json match {
case _: Json.Obj => None
case notAnObject => Some(notAnObject)
}
} and used it as: def foo(json: Json): Either[Throwable, SomeClass] = json match {
case NonObj(json) => Left(MismatchError(s"$json was not '{…}'"))
case j: Json.Obj =>
// very
// long
// body
// …
} and was surprised to see warnings like:
|
@hochgi AFAIK it doesn't peer into your extractor to see what it handles. Pattern matching is mysterious, so your question would be helpful on the forum. I don't know where these nuances are described in docs; my sense is that they try to make it "just work", with regard to warnings. This ticket is about something entirely different. |
reproduction steps
using any version of Scala
problem
SeqExtractor is irrefutable, and the three cases together are exhaustive, but we fail to recognize that.
note
Matching on List can work around that by matching on Cons or Nil exhaustively with
List(1) match {
case Nil => 0 // or List() due to rewrite
case head :: Nil => 1
case head :: second :: tail => 2
}
Spun out of #12240
The text was updated successfully, but these errors were encountered: