How to use switch/case (simple pattern matching) in Scala?

I've found myself stuck on a very trivial thing :-]

I've got an enum:

 object Eny extends Enumeration {
      type Eny = Value
      val FOO, BAR, WOOZLE, DOOZLE = Value
    }

In a code I have to convert it conditionally to a number (varianr-number correspondence differs on context). I write:

val en = BAR
val num = en match {
  case FOO => 4
  case BAR => 5
  case WOOZLE => 6
  case DOOZLE => 7
}

And this gives me an "unreachable code" compiler error for every branch but whatever is the first ("case FOO => 4" in this case). What am I doing wrong?

43
задан Yogesh Darji 7 January 2017 в 03:35
поделиться