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

Spurious exhaustivity warning on quote API + union types #12020

Closed
japgolly opened this issue Apr 8, 2021 · 2 comments · Fixed by #12059
Closed

Spurious exhaustivity warning on quote API + union types #12020

japgolly opened this issue Apr 8, 2021 · 2 comments · Fixed by #12059

Comments

@japgolly
Copy link
Contributor

japgolly commented Apr 8, 2021

Compiler version

Both:

  • 3.0.0-RC1
  • 3.0.1-RC1-bin-20210402-775d881-NIGHTLY

Minimized code

import scala.quoted.*

def qwe(using Quotes) = {
  import quotes.reflect.*

  def ko_1(param: ValDef | TypeDef) =
    param match {
      case _: ValDef =>
      case _: TypeDef =>
    }

  def ko_2(params: List[ValDef] | List[TypeDef]) =
    params.map {
      case x: ValDef =>
      case y: TypeDef =>
    }
}

Output

[warn] -- [E029] Pattern Match Exhaustivity Warning: /home/golly/scala3bug/sbt/src/main/scala/asd.scala:7:4 
[warn] 7 |    param match {
[warn]   |    ^^^^^
[warn]   |    match may not be exhaustive.
[warn]   |
[warn]   |    It would fail on pattern case: _: ValDef, _: TypeDef
[warn] -- [E029] Pattern Match Exhaustivity Warning: /home/golly/scala3bug/sbt/src/main/scala/asd.scala:14:6 
[warn] 14 |      case x: ValDef =>
[warn]    |      ^
[warn]    |      match may not be exhaustive.
[warn]    |
[warn]    |      It would fail on pattern case: _: ValDef, _: TypeDef
[warn] two warnings found

Expectation

No warnings.

@japgolly
Copy link
Contributor Author

japgolly commented Apr 8, 2021

Note: the reason I included two examples is because

  • in ko_1 the param itself is annotated as not being exhaustive (good placement)
  • in ko_2 the first case clause is annotated as not being exhaustive (incorrect placement) - param should be annotated

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Apr 8, 2021

The root of this issue is that TypeTest is not marked as being exhaustive. Also see #12026 and #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 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
@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