Skip to content

Commit 63b2610

Browse files
authored
Merge pull request #5071 from dotty-staging/switches
More tests for switches
2 parents a31ea22 + 215e879 commit 63b2610

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

tests/untried/neg/switch.scala renamed to tests/neg-custom-args/fatal-warnings/switches.scala

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,25 @@ object Main {
2525
}
2626

2727
// has a guard, but since SI-5830 that's ok
28-
def succ_guard(c: Char) = (c: @switch) match {
29-
case 'A' | 'B' | 'C' => true
30-
case x if x == 'A' => true
31-
case _ => false
32-
}
28+
// PENDING: #5070
29+
// def succ_guard(c: Char) = (c: @switch) match {
30+
// case 'A' | 'B' | 'C' => true
31+
// case x if x == 'A' => true
32+
// case _ => false
33+
// }
3334

3435
// throwing in @unchecked on the next two to make sure
3536
// multiple annotations are processed correctly
3637

3738
// thinks a val in an object is constant... so naive
38-
def fail2(c: Char) = (c: @switch @unchecked) match {
39+
def fail1(c: Char) = (c: @switch @unchecked) match { // error: Could not emit switch for @switch annotated match
3940
case 'A' => true
4041
case Other.C1 => true
4142
case _ => false
4243
}
4344

4445
// more naivete
45-
def fail3(c: Char) = (c: @unchecked @switch) match {
46+
def fail2(c: Char) = (c: @unchecked @switch) match { // error: Could not emit switch for @switch annotated match
4647
case 'A' => true
4748
case Other.C3 => true
4849
case _ => false
@@ -63,4 +64,14 @@ object Main {
6364
case 5|6|7|8 => 100
6465
case _ => -1
6566
}
67+
68+
def fail3(x: Any) = (x: @switch) match { // error: Could not emit switch for @switch annotated match
69+
case 1 | 2 | 3 => true
70+
case _ => false
71+
}
72+
73+
def fail4(x: AnyVal) = (x: @switch) match { // error: Could not emit switch for @switch annotated match
74+
case 1 | 2 | 3 => true
75+
case _ => false
76+
}
6677
}

tests/pos-special/fatal-warnings/switches.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ class Test {
2323
case 14 => 4
2424
case _ => 5
2525
}
26+
27+
def test4(x: Byte): Boolean = (x: @switch) match {
28+
case 1 | 2 | 3 => true
29+
case _ => false
30+
}
31+
32+
def test5(x: Short): Boolean = (x: @switch) match {
33+
case 1 | 2 | 3 => true
34+
case _ => false
35+
}
2636
}
2737

2838
object Test {

0 commit comments

Comments
 (0)