Skip to content

Incorrect union type exhaustivity warning (Nested pattern) #12808

Closed
@Swoorup

Description

@Swoorup

Compiler version

3.0.1-RC1

Minimized code

import scala.reflect.Typeable

case class Err1()
case class Err2()

def handleError[A: Typeable, B: Typeable](x: Either[A | B, Nothing]): Unit =
  x match // false alarm warning: It would fail on pattern case: Left(_)
    case Left(e: A)  => println("A")
    case Left(_: B) => println("B")
    case Right(_)    => println("Nothing")

handleError[Err1, Err2](Left(Err1())) // prints A
handleError[Err1, Err2](Left(Err2())) // prints B

Output

match may not be exhaustive.

It would fail on pattern case: Left(_)

Expectation

As all cases are handled no warnings need to be generated.

Unrelated question, but shouldn't removing Right be also fine? since it is of Nothing type? If you remove the last, the compiler gives out warning for Right pattern as well. (Looks like scala 2 has the same issue for this)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions