-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #12337: Enable exhaustivity check for case classes with checkable components #12377
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
Conversation
…kable components This aligns with Scala 2 behavior.
sealed trait Status | ||
object Status { | ||
case object Active extends Status | ||
case object Inactive extends Status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can one of these case object
be case class
instead to make sure it works for case class
as well?
e.g.)
sealed trait Status
object Status {
case class Active(since: Int) extends Status
case object Inactive extends Status
}
case class Foo(status: Status)
def bar(foo: Foo): Unit = foo match {
case Foo(Status.Active(2000)) =>
println("active since 2000")
}
// Expected:
// warning: match may not be exhaustive.
// It would fail on the following inputs: Foo(Active((x: Int forSome x not in 2000))), Foo(Inactive)
// def bar(foo: Foo): Unit = foo match {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or probably adding separate cases for case class
and case object
might be better?
e.g.)
sealed trait Status
object Status {
case class Active(since: Int) extends Status
case object Inactive extends Status
}
case class Foo(status: Status)
def bar(foo: Foo): Unit = foo match {
case Foo(Status.Active(since)) =>
println(s"active since $since")
}
// Expected:
// warning: match may not be exhaustive.
// It would fail on the following input: Foo(Inactive)
// def bar(foo: Foo): Unit = foo match {
def baz(foo: Foo): Unit = foo match {
case Foo(Status.Active(2000)) =>
println("active since 2000")
case Foo(Status.Inactive) =>
println("inactive")
}
// Expected:
// warning: match may not be exhaustive.
// It would fail on the following input: Foo(Active((x: Int forSome x not in 2000)))
// def baz(foo: Foo): Unit = foo match {
Thanks @dwijnand ! |
@liufengyun @dwijnand Thank you! |
…check This is a regression introduced in scala#12377.
Fix #12337: Enable exhaustivity check for case classes with checkable components
This aligns with Scala 2 behavior.