summaryrefslogtreecommitdiff
path: root/test/files/neg
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2014-09-29 17:52:40 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2014-10-06 20:56:32 +0200
commit0c25979244877b4431066700a6e945f145771c3c (patch)
tree92d631fc91e90c55508eda2b4aa460c2ba29658c /test/files/neg
parenta52db7f1639c6d48eaa64ae609385a60467fd566 (diff)
downloadscala-0c25979244877b4431066700a6e945f145771c3c.tar.gz
scala-0c25979244877b4431066700a6e945f145771c3c.tar.bz2
scala-0c25979244877b4431066700a6e945f145771c3c.zip
SI-8731 warning if @switch is ignored
For matches with two or fewer cases, @switch is ignored. This should not happen silently.
Diffstat (limited to 'test/files/neg')
-rw-r--r--test/files/neg/t6902.scala2
-rw-r--r--test/files/neg/t8731.check9
-rw-r--r--test/files/neg/t8731.flags1
-rw-r--r--test/files/neg/t8731.scala15
4 files changed, 26 insertions, 1 deletions
diff --git a/test/files/neg/t6902.scala b/test/files/neg/t6902.scala
index ce5ff8b6fb..627c324279 100644
--- a/test/files/neg/t6902.scala
+++ b/test/files/neg/t6902.scala
@@ -16,7 +16,7 @@ object Test {
// at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:50)
// at scala.tools.nsc.Global.abort(Global.scala:249)
// at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$jcode$.emitSWITCH(GenASM.scala:1850)
- ((1: Byte): @unchecked @annotation.switch) match {
+ ((1: Byte): @unchecked) match {
case 1 => 2
case 1 => 3 // crash
}
diff --git a/test/files/neg/t8731.check b/test/files/neg/t8731.check
new file mode 100644
index 0000000000..2a9af475fc
--- /dev/null
+++ b/test/files/neg/t8731.check
@@ -0,0 +1,9 @@
+t8731.scala:5: warning: matches with two cases or fewer are emitted using if-then-else instead of switch
+ def f(x: Int) = (x: @annotation.switch) match {
+ ^
+t8731.scala:10: warning: could not emit switch for @switch annotated match
+ def g(x: Int) = (x: @annotation.switch) match {
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/t8731.flags b/test/files/neg/t8731.flags
new file mode 100644
index 0000000000..e8fb65d50c
--- /dev/null
+++ b/test/files/neg/t8731.flags
@@ -0,0 +1 @@
+-Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/t8731.scala b/test/files/neg/t8731.scala
new file mode 100644
index 0000000000..d93fe706ad
--- /dev/null
+++ b/test/files/neg/t8731.scala
@@ -0,0 +1,15 @@
+class C {
+ // not a compile-time constant due to return type
+ final val K: Int = 20
+
+ def f(x: Int) = (x: @annotation.switch) match {
+ case K => 0
+ case 2 => 1
+ }
+
+ def g(x: Int) = (x: @annotation.switch) match {
+ case K => 0
+ case 2 => 1
+ case 3 => 2
+ }
+}