Skip to content
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

incorrect union type exhaustive match warning with ClassTag #11541

Closed
bohonghuang opened this issue Feb 26, 2021 · 3 comments · Fixed by #17385
Closed

incorrect union type exhaustive match warning with ClassTag #11541

bohonghuang opened this issue Feb 26, 2021 · 3 comments · Fixed by #17385

Comments

@bohonghuang
Copy link

Compiler version

3.0.0-RC1

Minimized code

import scala.reflect.ClassTag

type A
given ClassTag[A] = ???
var a: A|Null = null
a match { //WARNING: match may not be exhaustive. It would fail on pattern case: _: A
  case null =>
  case a: A =>
}
@nicolasstucki
Copy link
Contributor

same issue with type test

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

@nicolasstucki
Copy link
Contributor

These are special cases as we know that ClassTag and TypeTest their spec guarantees that they will match all A.

@liufengyun
Copy link
Contributor

We will be able to do this with #11186 , the concrete test case: f18ad26

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
liufengyun added a commit to dotty-staging/dotty that referenced this issue May 1, 2023
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants