Skip to content

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

Merged
merged 1 commit into from
Mar 1, 2021
Merged

Add test for t12237 #11528

merged 1 commit into from
Mar 1, 2021

Conversation

liufengyun
Copy link
Contributor

Add test for t12237 to avoid regression

Original issue:
scala/bug#12237

Original issue:
scala/bug#12237
@@ -0,0 +1 @@
21: Pattern Match Exhaustivity: Root, PathAndQuery./(_, _), PathAndQuery.===(_, _), PathAndQuery.:&(_, PathAndQuery.===(_, _)), PathAndQuery.+?(_, PathAndQuery.===(_, _))
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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"?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

@nicolasstucki nicolasstucki left a 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?

@dwijnand
Copy link
Member

dwijnand commented Mar 1, 2021

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.

@liufengyun
Copy link
Contributor Author

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.

@liufengyun liufengyun merged commit 0d6c926 into scala:master Mar 1, 2021
@liufengyun liufengyun deleted the fix-t12237 branch March 1, 2021 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants