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

Exhaustiveness test not working for sealed classes defined inside a function #9573

Closed
scabug opened this issue Nov 28, 2015 · 1 comment
Closed
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Nov 28, 2015

Scala 2.11.7 doesn't warn me that the match may not be exhaustive on the following code snippet:

class Foo {

  def foo = {
    abstract sealed class Animal
    case class Goat(age: Int) extends Animal
    case class Horse(age: Int) extends Animal

    val x: Animal = Goat(1)
    x match {
      case Goat(_)  println("a goat")
    }
  }
}

When I move the sealed class hierarchy outside the foo function, it warns me correctly.

class Foo {

  abstract sealed class Animal
  case class Goat(age: Int) extends Animal
  case class Horse(age: Int) extends Animal

  def foo = {
    val x: Animal = Goat(1)
    x match {
      case Goat(_)  println("a goat")
    }
  }
}

Foo.scala:11: match may not be exhaustive
[warn] It would fail on the following input: Horse(_)
[warn] x match {
[warn] ^
[warn] one warning found

@scabug
Copy link
Author

scabug commented Nov 28, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9573?orig=1
Reporter: Tomáš Dvořák (dvtomas)
Affected Versions: 2.11.7

@scabug scabug closed this as completed Nov 9, 2016
@scabug scabug added the patmat label Apr 7, 2017
@scabug scabug added this to the 2.12.0 milestone Apr 7, 2017
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

1 participant