-
Notifications
You must be signed in to change notification settings - Fork 1.1k
No warning is triggered for non-exhaustive pattern matching on case class field #12337
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
Comments
Exhaustivity check is not triggered since Changing sealed trait Status
object Status {
case object Active extends Status
case object Inactive extends Status
}
sealed case class Foo(status: Status)
def bar(user: Foo): Unit = user match {
case Foo(Status.Active) =>
println("active")
// no compile-time warning for missing Status.Inactive case
} -- [E029] Pattern Match Exhaustivity Warning: examples/i12337.scala:8:27 -------
8 |def bar(user: Foo): Unit = user match {
| ^^^^
| match may not be exhaustive.
|
| It would fail on pattern case: Foo(Inactive) |
@liufengyun Is it a changed behavior in Scala 3? The exactly the same code as mine in Scala 2 triggers non-exhaustive warning. |
I don't think it's changed intentionally. It's just not well specified whether we should perform more checks in the absence of |
@liufengyun Here is the same code in Scala 2.13.5. As you can see, the non-exhaustive warning is triggered. |
|
@som-snytt Thanks. Yeah I forgot to mention that it triggers the warning in Scala 2 without |
…kable components This aligns with Scala 2 behavior.
Fix #12337: Enable exhaustivity check for case classes with checkable components
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
3.0.0-RC3
fromprint scalaVersion
onsbt
console.Minimized code
scalacOptions
hasNOTE:
Replacing the
Status
above with theenum
like below doesn't make any difference.final case class
(i.e.final case class Foo(status: Status)
) makes no difference.Output
It compiles without any warning or error even with
-Xfatal-warnings
, and it results in the following runtime error.Expectation
The compile-time warning like
(or the compile-time error with
"-Xfatal-warnings"
compiler option)The text was updated successfully, but these errors were encountered: