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 exhaustiveness warnings include impossible types #7285

Closed
scabug opened this issue Mar 22, 2013 · 4 comments
Closed

pattern matcher exhaustiveness warnings include impossible types #7285

scabug opened this issue Mar 22, 2013 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Mar 22, 2013

scala> object Test {
  sealed abstract class BarrierDirection

  object BarrierDirection {
    case object Down extends BarrierDirection {
    }

    case object Up extends BarrierDirection {
    }

    (d1: BarrierDirection, d2: BarrierDirection) =>
      (d1, d2) match {
        case (Up, Up) | (Down, Down) => false
        case (Down, Up)              => true
        case (Up, Down)              => false
      }
  }
}
<console>:22: warning: match may not be exhaustive.
It would fail on the following inputs: (BarrierDirection(), Down), (BarrierDirection(), Up), (Down, BarrierDirection()), (Down, BarrierDirection()), (Down, Down), (Down, Down), (Down, Down), (Down, Up), (Down, Up), (Up, BarrierDirection()), (Up, Down), (Up, Down)
             (d1, d2) match {
             ^
scala> object Test {
  sealed abstract class BarrierDirection

  object BarrierDirection {
    case object Down extends BarrierDirection {
    }

    case object Up extends BarrierDirection {
    }

    (d1: BarrierDirection, d2: BarrierDirection) =>
      (d1) match {
        case Up | Down => false
      }
  }
}
<console>:22: warning: match may not be exhaustive.
It would fail on the following inputs: Down, Up
             (d1) match {
              ^
object Test {
  sealed abstract class BarrierDirection

  object BarrierDirection {
    case object Down extends BarrierDirection

    (d1: BarrierDirection, d2: BarrierDirection) =>
      (d1, d2) match {
        case (Down, Down)              => false
      }
  }
}

// <console>:17: warning: match may not be exhaustive.
// It would fail on the following inputs: (Down, Down), (Down, Down), (Down, Down)
//              (d1, d2) match {
//              ^
@scabug
Copy link
Author

@scabug scabug commented Mar 22, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7285?orig=1
Reporter: @retronym
Affected Versions: 2.10.1
See #6146

@scabug
Copy link
Author

@scabug scabug commented Mar 22, 2013

@retronym said (edited on Mar 22, 2013 1:23:28 PM UTC):
By contrast, this is okay:

scala>

scala> object Test {
  sealed abstract class BarrierDirection

  object BarrierDirection {
    case object Down extends BarrierDirection {
    }

    case object Up extends BarrierDirection {
    }

  }
  import Test.BarrierDirection._
  (d1: BarrierDirection, d2: BarrierDirection) =>
    (d1, d2) match {
      case (Up, Up) | (Down, Down) => false
      case (Down, Up)              => true
      case (Up, Down)              => false
    }
}
defined module Test

@scabug
Copy link
Author

@scabug scabug commented Mar 23, 2013

@scabug
Copy link
Author

@scabug scabug commented Mar 23, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants