You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code (here on Scastie) generates an exhaustivity warning that seems unjustified:
sealedabstractclassMaybe[A]
finalcaseclassJust[A](a: A) extendsMaybe[A]
classEmpty[A] extendsMaybe[A]
objectEmpty {
defapply[A]():Maybe[A] =newEmpty[A]
defunapply[A](e: Empty[A]):Some[Unit] =Some(())
}
objectTest {
vala:Maybe[Int] =Just(2)
defmain(args: Array[String]):Unit= a match {
caseJust(_) =>// case Empty(_) => // okcaseEmpty(()) =>// match may not be exhaustive. It would fail on: Empty(_)
}
}
Also (regardless of the fact that the warning is spurious), the error message says it would "fail on Empty(_)," but this is not even a valid expression (as in, I can't write val x = Empty(y)). If warnings are supposed to refer to patterns as opposed to expressions, maybe the message should read something like "pattern case Empty(_) not handled" instead.
The text was updated successfully, but these errors were encountered:
Unit is not technically a singleton type, but it should behave like one for the purpose of exhaustiveness checking. However, we don't seem to handle singleton types for exhaustiveness checks currently:
objectTest {
deffoo(x: Option[1]) = x match {
caseSome(1) =>caseNone=>
}
}
2|deffoo(x: Option[1]) = x match {
|^|match may not be exhaustive.
||It would fail on: Some(_)
smarter
changed the title
Spurious exhaustive pattern matching warning?
Exhaustiveness checker needs special rules for singleton types
Apr 2, 2018
The following code (here on Scastie) generates an exhaustivity warning that seems unjustified:
Also (regardless of the fact that the warning is spurious), the error message says it would "fail on
Empty(_)
," but this is not even a valid expression (as in, I can't writeval x = Empty(y)
). If warnings are supposed to refer to patterns as opposed to expressions, maybe the message should read something like "pattern caseEmpty(_)
not handled" instead.The text was updated successfully, but these errors were encountered: