diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-02-13 11:54:10 +0100 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-02-17 14:19:02 +0100 |
commit | a57ac60dbb115b90ca1ccc9944199bf3e82d517d (patch) | |
tree | 680f66ee9f6970e16d2d0ff89759d58010acc6bd /test/files/run | |
parent | 5efc2df71a517b0cb7d0abc828a580936befe5aa (diff) | |
download | scala-a57ac60dbb115b90ca1ccc9944199bf3e82d517d.tar.gz scala-a57ac60dbb115b90ca1ccc9944199bf3e82d517d.tar.bz2 scala-a57ac60dbb115b90ca1ccc9944199bf3e82d517d.zip |
[vpm] working type switch for try/catch
catch handlers are now also translated by the virtualizing pattern matcher
emit type-based switches when possible, fallback to catch-all with full pattern match
(the logic used to emit constant-based switches was generalized to type-based switches,
abstracting out how to refer to the scrutinee and the shape of a default/catch-all case)
this was the last missing piece of essential functionality
now the virtualizing pattern matcher and the old one are mutually exclusive:
-Yvirtpatmat disables the old matcher logic completely
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/virtpatmat_switch.scala | 8 | ||||
-rw-r--r-- | test/files/run/virtpatmat_try.check | 2 | ||||
-rw-r--r-- | test/files/run/virtpatmat_try.flags | 1 | ||||
-rw-r--r-- | test/files/run/virtpatmat_try.scala | 47 |
4 files changed, 57 insertions, 1 deletions
diff --git a/test/files/run/virtpatmat_switch.scala b/test/files/run/virtpatmat_switch.scala index 2e2c31e8e5..1329c19d0f 100644 --- a/test/files/run/virtpatmat_switch.scala +++ b/test/files/run/virtpatmat_switch.scala @@ -14,9 +14,15 @@ object Test extends App { case 'b' => "got b" case _ => "got some letter" } + + def byteSwitch(x: Byte) = x match { + case 'a' => "got a" + case 'b' => "got b" + case _ => "got some letter" + } println(charSwitch('a')) - println(charSwitch('b')) + println(byteSwitch('b')) println(charSwitch('z')) def implicitDefault(x: Int) = x match { diff --git a/test/files/run/virtpatmat_try.check b/test/files/run/virtpatmat_try.check new file mode 100644 index 0000000000..80ebbf494a --- /dev/null +++ b/test/files/run/virtpatmat_try.check @@ -0,0 +1,2 @@ +meh +B diff --git a/test/files/run/virtpatmat_try.flags b/test/files/run/virtpatmat_try.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/run/virtpatmat_try.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/run/virtpatmat_try.scala b/test/files/run/virtpatmat_try.scala new file mode 100644 index 0000000000..46e67cb72e --- /dev/null +++ b/test/files/run/virtpatmat_try.scala @@ -0,0 +1,47 @@ +object Test extends App { + case class A(val x: String) extends Throwable + class B extends Exception { override def toString = "B" } + def bla = 0 + + try { + throw new A("meh") + } catch { // this should emit a "catch-switch" + case y: A => println(y.x) + case (_ : A | _ : B) => println("B") + case _ => println("other") + } + + try { + throw new B() + } catch { // case classes and alternative flattening aren't supported yet, but could be in principle + // case A(x) => println(x) + case y: A => println(y.x) + case x@((_ : A) | (_ : B)) => println(x) + case _ => println("other") + } + + def simpleTry { + try { + bla + } catch { + case x: Exception if x.getMessage == "test" => println("first case " + x) + case x: Exception => println("second case " + x) + } + } + + def typedWildcardTry { + try { bla } catch { case _: ClassCastException => bla } + } + + def wildcardTry { + try { bla } catch { case _ => bla } + } + + def tryPlusFinally { + try { bla } finally { println("finally") } + } + + def catchAndPassToLambda { + try { bla } catch { case ex: Exception => val f = () => ex } + } +}
\ No newline at end of file |