-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add test for t12237 #11528
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
Add test for t12237 #11528
Conversation
Original issue: scala/bug#12237
@@ -0,0 +1 @@ | |||
21: Pattern Match Exhaustivity: Root, PathAndQuery./(_, _), PathAndQuery.===(_, _), PathAndQuery.:&(_, PathAndQuery.===(_, _)), PathAndQuery.+?(_, PathAndQuery.===(_, _)) |
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.
Is this the right expected result? What does PathAndQuery./(_, _)
mean? Because the first case is matching values that are PathAndQuery./
. Similarly PathAndQuery.:&(_, PathAndQuery.===(_, _))
and PathAndQuery.+?(_, PathAndQuery.===(_, _))
. I don't understand what the check file is asserting.
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.
Yes, it's the correct expect file, PathAndQuery./(_, _)
means that pattern is not exhaustive. The test is to defend against compiler hangs.
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.
PathAndQuery./(_, _)
means that pattern is not exhaustive.
I see. (Perhaps reporting PathAndQuery.:&(_, _)
and PathAndQuery.+?(_, _)
might be more uniform?)
I guess the Scala 3 checker doesn't try to give good counter-examples like Scala 2, which tries to do something like Root / "page" / x forSome x != "1"
?
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.
We would like to have refined counter-examples as in Scala 2. However, we could not figure out how to make it principled. For example, given the following example:
object Even {
def unapply(x: Int): Option[Int] = ???
}
class Test {
def foo(x: Option[Option[Int]]): Unit =
x match {
case Some(Some(5)) =>
case Some(Some(Even(10))) =>
case None =>
}
}
It's unclear how to handle extractors in the warnings. Even if it's possible to be more principled, there's the worry that the message gets messy, thus difficult to read.
Meanwhile, even with refined counter-examples, users still need to check the existing patterns. Due to the considerations, we only show general counter examples.
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.
Yeah, Scala 2's counter-example generation definitely doesn't handle extractors: it's all field based (for case classes) so it has no chance - it needs to be revisited. But it does a good job for case classes I say. It seems to be to be a good thing to generalise case class's unapply/extraction with the "product match" extractors, but it seems like discarding that knowledge for counter-example generation is lossy and thus a shame.
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.
It is good as a regression test.
We still need to follow up on the discussion. @liufengyun should we open an issue for this?
The discussion is more by-the-by, not a blocker to landing this. I'm not even sure if it's issue-worthy, as I'm not sure how valuable it ends up being to users to have the compiler construct precise counter-examples, like Scala 2 does. |
Thanks @dwijnand . Let's think about how to improve this together when there is a strong need for it. |
Add test for t12237 to avoid regression
Original issue:
scala/bug#12237