Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect GADT pattern exhaustivity warning #7524

Closed
bishabosha opened this issue Nov 8, 2019 · 5 comments · Fixed by #16169
Closed

Incorrect GADT pattern exhaustivity warning #7524

bishabosha opened this issue Nov 8, 2019 · 5 comments · Fixed by #16169

Comments

@bishabosha
Copy link
Member

bishabosha commented Nov 8, 2019

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

@bishabosha
Copy link
Member Author

bishabosha commented Oct 16, 2020

This one works for the type pattern

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]])
  }
}

@smarter
Copy link
Member

smarter commented May 5, 2021

@abgruszecki abgruszecki self-assigned this on Mar 19, 2020

@abgruszecki Did you have an angle of attack for this issue? Maybe @liufengyun could help?

@abgruszecki
Copy link
Contributor

I think I just assigned this issue to myself because otherwise it'd simply get lost.

@bishabosha
Copy link
Member Author

another example in 3.0.1-RC1:

object Main extends App:
   enum Extends[A, B]:
     case Ev[B, A <: B]() extends (A Extends B)

     def cast(a: A): B = this match {
       case Extends.Ev() => a
     }

@liufengyun
Copy link
Contributor

liufengyun commented Jun 17, 2021

This seems to be related to #9682. We need to rethink whether using wildApprox is appropriate in TypeOps.instantiateToSubtype. It also interferes with the changes we did in #8698 to support #8690.

@dwijnand dwijnand linked a pull request Oct 11, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants