diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-10-07 12:47:22 +0200 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-10-07 12:47:22 +0200 |
commit | d4601babe3b79e6cd354ed4e9fcd5feaaa47d2b0 (patch) | |
tree | 6f6a7f72f0ee5fea936bbc941874b8d37175a850 /test/files | |
parent | d028d89ece11a886cce88e2c0e1d8443d6271e0c (diff) | |
parent | 0c25979244877b4431066700a6e945f145771c3c (diff) | |
download | scala-d4601babe3b79e6cd354ed4e9fcd5feaaa47d2b0.tar.gz scala-d4601babe3b79e6cd354ed4e9fcd5feaaa47d2b0.tar.bz2 scala-d4601babe3b79e6cd354ed4e9fcd5feaaa47d2b0.zip |
Merge pull request #4016 from lrytz/t8731
SI-8731 warning if @switch is ignored
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/t6902.scala | 2 | ||||
-rw-r--r-- | test/files/neg/t8731.check | 9 | ||||
-rw-r--r-- | test/files/neg/t8731.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t8731.scala | 15 | ||||
-rw-r--r-- | test/files/pos/switch-small.flags | 1 | ||||
-rw-r--r-- | test/files/pos/switch-small.scala | 8 | ||||
-rw-r--r-- | test/files/run/t5830.check | 1 | ||||
-rw-r--r-- | test/files/run/t5830.scala | 13 | ||||
-rw-r--r-- | test/files/run/t6011c.scala | 2 |
9 files changed, 34 insertions, 18 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 + } +} diff --git a/test/files/pos/switch-small.flags b/test/files/pos/switch-small.flags deleted file mode 100644 index 85d8eb2ba2..0000000000 --- a/test/files/pos/switch-small.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings diff --git a/test/files/pos/switch-small.scala b/test/files/pos/switch-small.scala deleted file mode 100644 index 9de9ca028e..0000000000 --- a/test/files/pos/switch-small.scala +++ /dev/null @@ -1,8 +0,0 @@ -import annotation._ - -object Test { - def f(x: Int) = (x: @switch) match { - case 1 => 1 - case _ => 2 - } -} diff --git a/test/files/run/t5830.check b/test/files/run/t5830.check index 675387eb8e..9260854676 100644 --- a/test/files/run/t5830.check +++ b/test/files/run/t5830.check @@ -1,5 +1,6 @@ a with oef a with oef +a with oef a def with oef def diff --git a/test/files/run/t5830.scala b/test/files/run/t5830.scala index 5d808bfa28..03b9c540e0 100644 --- a/test/files/run/t5830.scala +++ b/test/files/run/t5830.scala @@ -1,12 +1,11 @@ import scala.annotation.switch object Test extends App { - // TODO: should not emit a switch - // def noSwitch(ch: Char, eof: Boolean) = (ch: @switch) match { - // case 'a' if eof => println("a with oef") // then branch - // } + def noSwitch(ch: Char, eof: Boolean) = ch match { + case 'a' if eof => println("a with oef") // then branch + } - def onlyThen(ch: Char, eof: Boolean) = (ch: @switch) match { + def onlyThen(ch: Char, eof: Boolean) = ch match { case 'a' if eof => println("a with oef") // then branch case 'c' => } @@ -18,7 +17,7 @@ object Test extends App { case 'c' => } - def defaultUnguarded(ch: Char, eof: Boolean) = (ch: @switch) match { + def defaultUnguarded(ch: Char, eof: Boolean) = ch match { case ' ' if eof => println("spacey oef") case _ => println("default") } @@ -44,7 +43,7 @@ object Test extends App { // case 'c' => // } - // noSwitch('a', true) + noSwitch('a', true) onlyThen('a', true) // 'a with oef' ifThenElse('a', true) // 'a with oef' ifThenElse('a', false) // 'a' diff --git a/test/files/run/t6011c.scala b/test/files/run/t6011c.scala index 0647e3f81a..96a685b9cf 100644 --- a/test/files/run/t6011c.scala +++ b/test/files/run/t6011c.scala @@ -6,7 +6,7 @@ object Test extends App { // 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 } |