diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2012-02-01 17:32:48 +0100 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2012-02-01 17:32:48 +0100 |
commit | 556dc8c5406f9ab9c9470ff22d430693f00d2807 (patch) | |
tree | adbf48374bfb115b0fba7fa680256d940daa5c31 /test | |
parent | 39457f6c85fc9764d714d52317edcd4300fd82b8 (diff) | |
download | scala-556dc8c5406f9ab9c9470ff22d430693f00d2807.tar.gz scala-556dc8c5406f9ab9c9470ff22d430693f00d2807.tar.bz2 scala-556dc8c5406f9ab9c9470ff22d430693f00d2807.zip |
Added a test-case for switches with Yvirtpatmat.
Added a bunch of tests that cover changes related
to switches that were applied to Yvirtpatmat
implementation.
Note: I didn't add those tests progressively because
my changes fix trees after typer phase but do not
affect resulting bytecode. How come? It's because
-Yvirtpatmat will emit pattern for switches and then
the old pattern matcher implementation would transform
them in the old fashion in explicitouter. We cannot
disable the old pattern matcher in explicitouter yet
because it doesn't handle patterns used for catching
exceptions.
Thus, consider this as a sign of the fact that Yvirtpatmat
is still work in progress.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/virtpatmat_switch.check | 7 | ||||
-rw-r--r-- | test/files/run/virtpatmat_switch.flags | 1 | ||||
-rw-r--r-- | test/files/run/virtpatmat_switch.scala | 32 |
3 files changed, 40 insertions, 0 deletions
diff --git a/test/files/run/virtpatmat_switch.check b/test/files/run/virtpatmat_switch.check new file mode 100644 index 0000000000..6ded95c010 --- /dev/null +++ b/test/files/run/virtpatmat_switch.check @@ -0,0 +1,7 @@ +zero +one +many +got a +got b +got some letter +scala.MatchError: 5 (of class java.lang.Integer)
\ No newline at end of file diff --git a/test/files/run/virtpatmat_switch.flags b/test/files/run/virtpatmat_switch.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/run/virtpatmat_switch.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/run/virtpatmat_switch.scala b/test/files/run/virtpatmat_switch.scala new file mode 100644 index 0000000000..2e2c31e8e5 --- /dev/null +++ b/test/files/run/virtpatmat_switch.scala @@ -0,0 +1,32 @@ +object Test extends App { + def intSwitch(x: Int) = x match { + case 0 => "zero" + case 1 => "one" + case _ => "many" + } + + println(intSwitch(0)) + println(intSwitch(1)) + println(intSwitch(10)) + + def charSwitch(x: Char) = x match { + case 'a' => "got a" + case 'b' => "got b" + case _ => "got some letter" + } + + println(charSwitch('a')) + println(charSwitch('b')) + println(charSwitch('z')) + + def implicitDefault(x: Int) = x match { + case 0 => 0 + } + + try { + implicitDefault(5) + } catch { + case e: MatchError => println(e) + } + +} |