summaryrefslogtreecommitdiff
path: root/test-nsc/files
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2005-11-16 16:40:15 +0000
committerIulian Dragos <jaguarul@gmail.com>2005-11-16 16:40:15 +0000
commit306e0e4e7a88a00eaac88820649aec407b170fbe (patch)
tree524e4a4479a9b0ab7560abb7717f30fce97b137a /test-nsc/files
parent19866718999792383b6b2dfce19b236fd2a591ed (diff)
downloadscala-306e0e4e7a88a00eaac88820649aec407b170fbe.tar.gz
scala-306e0e4e7a88a00eaac88820649aec407b170fbe.tar.bz2
scala-306e0e4e7a88a00eaac88820649aec407b170fbe.zip
Test that try-catches get lifted when necessary.
Diffstat (limited to 'test-nsc/files')
-rw-r--r--test-nsc/files/run/try.check5
-rw-r--r--test-nsc/files/run/try.scala91
2 files changed, 96 insertions, 0 deletions
diff --git a/test-nsc/files/run/try.check b/test-nsc/files/run/try.check
new file mode 100644
index 0000000000..30d3881906
--- /dev/null
+++ b/test-nsc/files/run/try.check
@@ -0,0 +1,5 @@
+1 + 1 = 2
+1 + 1 = 2
+1 + 1 = 2
+
+1 + 1 = 2
diff --git a/test-nsc/files/run/try.scala b/test-nsc/files/run/try.scala
new file mode 100644
index 0000000000..bc339b71da
--- /dev/null
+++ b/test-nsc/files/run/try.scala
@@ -0,0 +1,91 @@
+object Test extends AnyRef with Application {
+ val x = 1;
+
+ def try1 = {
+ Console.print("1 + 1 = ");
+ Console.println(1 + (
+ try {
+ x;
+ } catch {
+ case _: Error => 1;
+ }
+ ));
+ }
+
+ def try2 = {
+ Console.print("1 + 1 = ");
+ Console.println(
+ (try { x } catch {
+ case _: Error => 1;
+ })
+ +
+ (try { x } catch {
+ case _: Error => 1;
+ })
+ );
+ }
+
+ var n = 0;
+
+ def try3 = {
+ Console.print("1 + 1 = ");
+ val x = try { 1 } catch {
+ case e: Error => 1;
+ }
+ this.n = try { 1 } catch {
+ case e: Error => 1;
+ }
+ Console.println(x + n);
+ }
+
+ var instance: AnyRef = null;
+
+ def try4 = {
+ if (instance == null) {
+ instance = try {
+ new String();
+ } catch {
+ case _ =>
+ val cs = "aaa";
+ if (cs.length() > 0) {
+ new String();
+ } else {
+ throw new Error("fatal error");
+ null
+ }
+ }
+ }
+ }
+
+ class A {
+ private val result = {
+ val y = try { x } catch {
+ case _: Error => 1;
+ };
+ x + y
+ }
+ Console.print("1 + 1 = ");
+ Console.println(result);
+ }
+
+/*
+ def finally1 = {
+ Console.print("1 + 1 = ");
+ Console.println(1 + (
+ try {
+ x
+ } finally {
+ ()
+ }
+ ));
+ }
+
+*/
+
+ try1;
+ try2;
+ try3;
+ Console.println;
+ new A();
+ ()
+}