scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Exhaustiveness checking shouldn't complain about uninhabited types #10143

Open scabug opened 7 years ago

scabug commented 7 years ago

Using shapeless's Coproduct, we get a warning that the match may not be exhaustive:

scala> import shapeless._
import shapeless._

scala> type IntOrString = Int :+: String :+: CNil
defined type alias IntOrString

scala> val value: IntOrString = Coproduct[IntOrString]("foo")
value: IntOrString = Inr(Inl(foo))

scala> value match {
     |   case Inl(i: Int) => println(s"I am an Int: $i")
     |   case Inr(Inl(s: String)) => println(s"I am a String: $s")
     | }
<console>:16: warning: match may not be exhaustive.
It would fail on the following input: Inr(Inr(_))
       value match {
       ^
I am a String: foo

Attempts to provide the last (useless) case now gives an "unreachable code" warning:

scala> value match {
     |   case Inl(i: Int) => println(s"I am an Int: $i")
     |   case Inr(Inl(s: String)) => println(s"I am a String: $s")
     |   case Inr(Inr(_: CNil)) => ???
     | }
<console>:19: warning: unreachable code
         case Inr(Inr(_: CNil)) => ???
                                   ^
I am a String: foo

It would be nice if the information used to provide the "unreachable code" warning negated the "match may not be exhaustive" warning.

scabug commented 7 years ago

Imported From: https://issues.scala-lang.org/browse/SI-10143?orig=1 Reporter: @dwijnand Affected Versions: 2.12.1