blob: a36cca78979458eaaf80e1d25823d8ee10560654 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
object Test {
def f(ch: Char): Any = ch match {
case 'a' => 1
case 'a' | 'c' => 1 // unreachable
}
// won't be compiled to a switch since it has an unreachable (duplicate) case
def f2(ch: Char): Any = (ch: @annotation.switch) match {
case 'a' | 'b' => 1
case 'b' | 'a' => 1 // unreachable
case _ =>
}
// s'all good
def f3(ch: Char): Any = (ch: @annotation.switch) match {
case 'a' | 'b' if (true: Boolean) => 1
case 'b' | 'a' => 1 // ok
case _ => // need third case to check switch annotation (two-case switches are always okay to compile to if-then-else)
}
def main(args: Array[String]): Unit = f('a')
}
|