Skip to content

False positive exhaustivity warning on GADTs #13548

Closed
@noelwelsh

Description

@noelwelsh

I have a case with exhaustivity checking complaining that an exhaustive match is not exhaustive. Amusingly, if I add a placeholder (case _ => ...) the compiler then complains that the placeholder is not reachable. I have checked this in Scala 3.0, 3.0.1, 3.0.2, and 3.1.0-RC2. The full code is in: https://github.com/noelwelsh/repast

Here is a minimization, which demonstrates the exhaustivity checking issue but not the issue with a placeholder. Tested in Scala 3.1.0-RC2:

enum Exhausted[S, A] {
  def parse(
      input: String,
      offset: Int): A = {
    this match {

      case Resume(p) => p.parse(input, offset)

      // case _ =>
      //   throw new IllegalStateException(
      //     "This case should never happen. It's only here to stop exhaustivity checking from complaining."
      // )
    }
  }
  case Resume[S, A](parser: Exhausted[A, A])
      extends Exhausted[A, A]
}

I can create a repo with this if useful.

The issue appears to be related to having two type parameters both having the same type. If I change extends Exhausted[A, A] to extends Exhausted[S, A] the error goes away.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions