Closed
Description
Minimized code
import scala.annotation.switch
sealed trait Fruit
object Fruit {
case object Apple extends Fruit
case object Banana extends Fruit
case object Orange extends Fruit
def isCitrus(fruit: Fruit): Boolean =
(fruit: @switch) match {
case Orange => true
case _ => false
}
}
Output
// Could not emit switch for @switch annotated match since there are not enough cases
Expectation
I would have expected this to work as it appears to on Scala 2. I can understand that there are only two cases in the match
statement versus three types of fruit but I would have hoped the compiler would be smart enough to know that using a wildcard is equivalent to matching against each of the remaining cases. If I enumerate them individually as in case Apple | Banana => ???
this works, but it doesn't seem like I should have to do that.