Skip to content

Incorrect GADT pattern exhaustivity warning #7524

Closed
@bishabosha

Description

@bishabosha

A simplification of #6088

minimized code

object GADT {
  import =:=._

  enum =:=[A, B] {
    case Refl[C]() extends (C =:= C)
  }

  def unwrap[A,B](opt: Option[A])(using ev: A =:= Option[B]): Option[B] = ev match {
    case Refl() => opt.flatMap(identity[Option[B]])
  }
}

error:

-- [E029] Pattern Match Exhaustivity Warning: GADT.scala:7:74 
7 |  def unwrap[A,B](opt: Option[A])(given ev: A =:= Option[B]): Option[B] = ev match {
  |                                                                          ^^
  |                               match may not be exhaustive.
  |
  |                               It would fail on pattern case: =:=.Refl()

The warning goes away if you make A contravariant.

expectation

No warning

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions