scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.83k stars 1.05k forks source link

Spurious exhaustivity warning on quote API + union types #12020

Closed japgolly closed 3 years ago

japgolly commented 3 years ago

Compiler version

Both:

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 commented 3 years ago

Note: the reason I included two examples is because

nicolasstucki commented 3 years ago

The root of this issue is that TypeTest is not marked as being exhaustive. Also see #12026 and #11541.