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

False exhaustiveness warning with inner case objects/classes #7298

Closed
scabug opened this issue Mar 25, 2013 · 3 comments
Closed

False exhaustiveness warning with inner case objects/classes #7298

scabug opened this issue Mar 25, 2013 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Mar 25, 2013

the following has an exhaustiveness warning in 2.10.1 but not in 2.10.0:

sealed trait Bool
object Bool {
  case object FALSE extends Bool
  case object TRUE extends Bool

  def show(b: Bool) = b match {
    case FALSE => "1"
    case TRUE  => "2"
  }
}

but this is ok:

sealed trait Bool
case object FALSE extends Bool
case object TRUE extends Bool

object Bool {
  def show(b: Bool) = b match {
    case FALSE => "1"
    case TRUE  => "2"
  }
}

warning is:

[info] Compiling 2 Scala sources to /Volumes/src/test/target/scala-2.10/classes...
[warn] /Volumes/src/test/src/main/scala/Bool.scala:6: match may not be exhaustive.
[warn] It would fail on the following inputs: FALSE, TRUE
[warn]   def show(b: Bool) = b match {
[warn]                       ^
[warn] one warning found

Note that if I change the inner case objects to case classes the warning remains.

@scabug
Copy link
Author

scabug commented Mar 25, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7298?orig=1
Reporter: Jed Wesley-Smith (jedws)
Affected Versions: 2.10.1

@scabug
Copy link
Author

scabug commented Mar 25, 2013

@retronym said (edited on Mar 25, 2013 9:03:05 AM UTC):
I found and fixed this a few days ago as #7285.

The workaround is to qualify the references to FALSE/TRUE. Also note that the bug doesn't occur for matches defined outside of Bool

sealed trait Bool
object Bool {
  case object FALSE extends Bool
  case object TRUE extends Bool

  def show(b: Bool) = b match {
    case Bool.FALSE => "1"
    case Bool.TRUE  => "2"
  }
}

object Test {
  import Bool._
  def show(b: Bool) = b match {
    case FALSE => "1"
    case TRUE  => "2"
  }
}

@scabug scabug closed this as completed Mar 25, 2013
@scabug
Copy link
Author

scabug commented Mar 25, 2013

Jed Wesley-Smith (jedws) said:
Thanks Jason.

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