Skip to content

TypeTest exhaustivity check #12026

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

Closed
nicolasstucki opened this issue Apr 8, 2021 · 1 comment · Fixed by #12059
Closed

TypeTest exhaustivity check #12026

nicolasstucki opened this issue Apr 8, 2021 · 1 comment · Fixed by #12059

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Apr 8, 2021

Compiler version

3.0.0-RC2

Minimized code

def test[A, B](a: A|B)(using reflect.TypeTest[Any, A], reflect.TypeTest[Any, B]) =
  a match {  // WARNING: match may not be exhaustive. It would fail on pattern case: _: A, _: B
    case a: A =>
    case b: B =>
  }

Output

match may not be exhaustive. It would fail on pattern case: _: A, _: B

Expectation

Should not warn.

A call to TypeTest.unapply should match all A as an a: A would if A was concrete, therefore it covers the type A. Same for B.

@nicolasstucki
Copy link
Contributor Author

A possible solution to this is #11186. But as it is a more contentious PR it might be good to special case the fix for this particular feature and generalize it later.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 9, 2021
Properly capture the semantics of `TypeTest` in the `Space` logic.
`TypeTest[S, T].unapply` is equivalent to (and mostly used as) a `_: T` pattern and therefore cover all `T`.

* Update the documentation to make this feature clearer
* Fixes scala#12026
* Fixes scala#12020
* Improves scala#11541
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 9, 2021
Properly capture the semantics of `TypeTest` in the `Space` logic.
`TypeTest[S, T].unapply` is equivalent to (and mostly used as) a `_: T` pattern and therefore covers all `T`.

* Update the documentation to make this feature clearer
* Fixes scala#12026
* Fixes scala#12020
* Improves scala#11541
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 9, 2021
Properly capture the semantics of `TypeTest` in the `Space` logic.
`TypeTest[S, T].unapply` is equivalent to (and mostly used as) a `_: T` pattern and therefore covers all `T`.

* Update the documentation to make this feature clearer
* Fixes scala#12026
* Fixes scala#12020
* Improves scala#11541
@nicolasstucki nicolasstucki added this to the 3.0.0 milestone Apr 12, 2021
@odersky odersky removed this from the 3.0.0 milestone Apr 12, 2021
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants