Skip to content

Incorrect exhaustivity warning when using opaque types with constraint and enums #22513

Open
@eejbyfeldt

Description

@eejbyfeldt

Compiler version

3.6.3

Minimized code

opaque type R[T] <: T = T

object Test {
  enum E:
    case E(a: Int)

  val v: R[E] = ???
  v match
    case E.E(_) =>
}

Output

[warn] ./opaque_subtype.scala:8:3
[warn] match may not be exhaustive.
[warn] 
[warn] It would fail on pattern case: _: R[E]
[warn]   v match
[warn] 

Expectation

The code should compile without warnings.

Adding the case from the exhaustive warning like this

opaque type R[T] <: T = T

object Test {
  enum E:
    case E(a: Int)

  val v: R[E] = ???
  v match
    case E.E(_) =>
    case _: R[E] => 
}

also does not compile with

[warn] ./dev/eejbyfeldt/scala_playground/opaque_subtype.scala:10:10
[warn] Unreachable case
[warn]     case _: R[E] =>
[warn] 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions