summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-07-16 04:56:04 -0700
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-07-16 04:56:04 -0700
commitd6e17dcc9af46d7f92b26063366f6c8dedae58e9 (patch)
tree2e35ae76b566bf6e2e24cebc3261f7cd1a8fdcbd /test
parent6d0d5054faab2c0d2d4c112def6d58f7965ad69b (diff)
parentef2bf411427624b77c4c48a7303176f1664321a2 (diff)
downloadscala-d6e17dcc9af46d7f92b26063366f6c8dedae58e9.tar.gz
scala-d6e17dcc9af46d7f92b26063366f6c8dedae58e9.tar.bz2
scala-d6e17dcc9af46d7f92b26063366f6c8dedae58e9.zip
Merge pull request #876 from adriaanm/ticket-6011b
SI-6011 switches: unreachability, guard-free form
Diffstat (limited to 'test')
-rw-r--r--test/files/neg/t5830.check5
-rw-r--r--test/files/neg/t6011.check10
-rw-r--r--test/files/neg/t6011.flags1
-rw-r--r--test/files/neg/t6011.scala23
-rw-r--r--test/files/neg/t6048.check10
-rw-r--r--test/files/neg/t6048.flags1
-rw-r--r--test/files/neg/t6048.scala22
-rw-r--r--test/files/run/t6011b.check1
-rw-r--r--test/files/run/t6011b.scala11
9 files changed, 83 insertions, 1 deletions
diff --git a/test/files/neg/t5830.check b/test/files/neg/t5830.check
index 85cb84378f..726fac2a1e 100644
--- a/test/files/neg/t5830.check
+++ b/test/files/neg/t5830.check
@@ -1,4 +1,7 @@
t5830.scala:6: error: unreachable code
case 'a' => println("b") // unreachable
^
-one error found
+t5830.scala:4: error: could not emit switch for @switch annotated match
+ def unreachable(ch: Char) = (ch: @switch) match {
+ ^
+two errors found
diff --git a/test/files/neg/t6011.check b/test/files/neg/t6011.check
new file mode 100644
index 0000000000..5b5a861e5b
--- /dev/null
+++ b/test/files/neg/t6011.check
@@ -0,0 +1,10 @@
+t6011.scala:4: error: unreachable code
+ case 'a' | 'c' => 1 // unreachable
+ ^
+t6011.scala:10: error: unreachable code
+ case 'b' | 'a' => 1 // unreachable
+ ^
+t6011.scala:8: error: could not emit switch for @switch annotated match
+ def f2(ch: Char): Any = (ch: @annotation.switch) match {
+ ^
+three errors found
diff --git a/test/files/neg/t6011.flags b/test/files/neg/t6011.flags
new file mode 100644
index 0000000000..e8fb65d50c
--- /dev/null
+++ b/test/files/neg/t6011.flags
@@ -0,0 +1 @@
+-Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/t6011.scala b/test/files/neg/t6011.scala
new file mode 100644
index 0000000000..a36cca7897
--- /dev/null
+++ b/test/files/neg/t6011.scala
@@ -0,0 +1,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')
+} \ No newline at end of file
diff --git a/test/files/neg/t6048.check b/test/files/neg/t6048.check
new file mode 100644
index 0000000000..051f41877e
--- /dev/null
+++ b/test/files/neg/t6048.check
@@ -0,0 +1,10 @@
+t6048.scala:3: error: unreachable code
+ case _ if false => x // unreachable
+ ^
+t6048.scala:8: error: unreachable code
+ case _ if false => x // unreachable
+ ^
+t6048.scala:14: error: unreachable code
+ case 5 if true => x // unreachable
+ ^
+three errors found
diff --git a/test/files/neg/t6048.flags b/test/files/neg/t6048.flags
new file mode 100644
index 0000000000..e8fb65d50c
--- /dev/null
+++ b/test/files/neg/t6048.flags
@@ -0,0 +1 @@
+-Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/t6048.scala b/test/files/neg/t6048.scala
new file mode 100644
index 0000000000..803e651d19
--- /dev/null
+++ b/test/files/neg/t6048.scala
@@ -0,0 +1,22 @@
+class A {
+ def f1(x: Int) = x match {
+ case _ if false => x // unreachable
+ case 5 => x
+ }
+
+ def f2(x: Int) = x match {
+ case _ if false => x // unreachable
+ case 5 if true => x
+ }
+
+ def f3(x: Int) = x match {
+ case _ => x
+ case 5 if true => x // unreachable
+ }
+
+ def test1(x: Int) = x match {
+ case c if c < 0 => 0
+ case 1 => 1
+ case _ => 2
+ }
+}
diff --git a/test/files/run/t6011b.check b/test/files/run/t6011b.check
new file mode 100644
index 0000000000..00750edc07
--- /dev/null
+++ b/test/files/run/t6011b.check
@@ -0,0 +1 @@
+3
diff --git a/test/files/run/t6011b.scala b/test/files/run/t6011b.scala
new file mode 100644
index 0000000000..3d405e0705
--- /dev/null
+++ b/test/files/run/t6011b.scala
@@ -0,0 +1,11 @@
+object Test extends App {
+ var cond = true
+
+ // should not generate a switch
+ def f(ch: Char): Int = ch match {
+ case 'a' if cond => 1
+ case 'z' | 'a' => 2
+ }
+
+ println(f('a') + f('z')) // 3
+} \ No newline at end of file