Skip to content

Incorrect MatchCaseUnreachable warning on Coproduct #3443

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

Closed
OlivierBlanvillain opened this issue Nov 8, 2017 · 0 comments
Closed

Incorrect MatchCaseUnreachable warning on Coproduct #3443

OlivierBlanvillain opened this issue Nov 8, 2017 · 0 comments

Comments

@OlivierBlanvillain
Copy link
Contributor

Here is an example where Dotty incorrectly reports an unreachable case in pattern marching:

object Test {
  // shapeless.Coproduct
  sealed trait Coproduct extends Product with Serializable
  sealed trait :+:[+H, +T <: Coproduct] extends Coproduct
  final case class Inl[+H, +T <: Coproduct](head : H) extends :+:[H, T]
  final case class Inr[+H, +T <: Coproduct](tail : T) extends :+:[H, T]
  sealed trait CNil extends Coproduct

  // Note that this only appears when T is a type parameter. Replaying T with
  // a concrete type (CNil or another :+:) leads to accurate warnnings
  def f[T <: Coproduct](fa: Int :+: T) =
    fa match {
      case Inl(x) => 1
      case Inr(x) => 2 // Dotty thinks this unreachable, but it is!
    }

  def main(args: Array[String]): Unit =
    assert(f(Inr(Inl(-1))) == 2) // Example of reachability
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants