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

Pattern-matcher emits spurious exhaustiveness warning #9399

Closed
scabug opened this issue Jul 14, 2015 · 4 comments
Closed

Pattern-matcher emits spurious exhaustiveness warning #9399

scabug opened this issue Jul 14, 2015 · 4 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jul 14, 2015

Using a similar type hierarchy to #9398, the following code produces a spurious exhaustiveness warning.

  sealed abstract class TA
  sealed abstract class TB extends TA
  case object A extends TA
  case object B extends TB

  sealed trait C
  case class CTA(id: Int, da: TA) extends C
  case class CTB(id: Int, da: TB) extends C

  val test: C => Unit = {
    case CTA(_, A) =>
    case CTA(_, B) =>
    case CTB(_, B) =>
  }

produces

match may not be exhaustive.
It would fail on the following input: CTB(_, _)
    val test: C => Unit = {
@scabug
Copy link
Author

scabug commented Jul 14, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9399?orig=1
Reporter: David Barri (japgolly)
Affected Versions: 2.11.7
See #9398, #9630

@scabug
Copy link
Author

scabug commented Jul 14, 2015

David Barri (japgolly) said:
Interestingly, it goes away if you change the order of cases. This produces no warning:

  val test: C => Unit = {
    case CTB(_, B) =>
    case CTA(_, B) =>
    case CTA(_, A) =>
  }

@scabug
Copy link
Author

scabug commented Jan 25, 2016

@retronym said:
My prototype fix for #9630 (linked from that ticket) also fixes this one. I'll update this ticket when we get that polished and merged.

A workaround is to avoid using the same name for the case class fields in sibling case classes.

sealed trait C
case class CTA(id: Int, da: TA) extends C
case class CTB(id1: Int, da1: TB) extends C

@scabug
Copy link
Author

scabug commented Jan 27, 2016

@retronym said:
scala/scala#4919

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants