aboutsummaryrefslogtreecommitdiff
path: root/tests/untried/neg/switch.scala
diff options
context:
space:
mode:
authorSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-12 22:44:33 +0100
committerSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-12 22:44:33 +0100
commit9ef5f6817688f814a3450126aa7383b0928e80a0 (patch)
tree5727a2f7f7fd665cefdb312af2785c692f04377c /tests/untried/neg/switch.scala
parent194be919664447631ba55446eb4874979c908d27 (diff)
downloaddotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.gz
dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.bz2
dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.zip
add tests from scala/test/files/{pos,neg}
with explicit Unit return type
Diffstat (limited to 'tests/untried/neg/switch.scala')
-rw-r--r--tests/untried/neg/switch.scala66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/untried/neg/switch.scala b/tests/untried/neg/switch.scala
new file mode 100644
index 000000000..a66ed768f
--- /dev/null
+++ b/tests/untried/neg/switch.scala
@@ -0,0 +1,66 @@
+import scala.annotation.switch
+
+// this is testing not so much how things ought to be but how they are;
+// the test is supposed to start failing if the behavior changes at all.
+object Other {
+ val C1 = 'P' // fails: not final
+ final val C2 = 'Q' // succeeds: singleton type Char('Q') inferred
+ final val C3: Char = 'R' // fails: type Char specified
+ final val C4 = '\u000A' // succeeds like C2 but more unicodey
+}
+
+object Main {
+ def succ1(c: Char) = (c: @switch) match {
+ case 'A' | 'B' | 'C' => true
+ case 'd' => true
+ case 'f' | 'g' => true
+ case _ => false
+ }
+
+ def succ2(c: Char) = (c: @switch) match {
+ case 'A' | 'B' | 'C' => true
+ case Other.C2 => true
+ case Other.C4 => true
+ case _ => false
+ }
+
+ // has a guard, but since SI-5830 that's ok
+ def succ_guard(c: Char) = (c: @switch) match {
+ case 'A' | 'B' | 'C' => true
+ case x if x == 'A' => true
+ case _ => false
+ }
+
+ // throwing in @unchecked on the next two to make sure
+ // multiple annotations are processed correctly
+
+ // thinks a val in an object is constant... so naive
+ def fail2(c: Char) = (c: @switch @unchecked) match {
+ case 'A' => true
+ case Other.C1 => true
+ case _ => false
+ }
+
+ // more naivete
+ def fail3(c: Char) = (c: @unchecked @switch) match {
+ case 'A' => true
+ case Other.C3 => true
+ case _ => false
+ }
+
+ // guard case done correctly
+ def succ3(c: Char) = (c: @switch) match {
+ case 'A' | 'B' | 'C' => true
+ case x => x == 'A'
+ }
+
+ // some ints just to mix it up a bit
+ def succ4(x: Int, y: Int) = ((x+y): @switch) match {
+ case 1 => 5
+ case 2 => 10
+ case 3 => 20
+ case 4 => 50
+ case 5|6|7|8 => 100
+ case _ => -1
+ }
+}