summaryrefslogtreecommitdiff
path: root/test/files/continuations-neg
diff options
context:
space:
mode:
authorphaller <hallerp@gmail.com>2012-07-23 14:03:22 +0200
committerphaller <hallerp@gmail.com>2012-08-08 16:24:29 +0200
commit75e36233a0ea290cee98a35bc295feed4b18237e (patch)
treea8950fa574a01f410765df6d1eda0ed918a8f4da /test/files/continuations-neg
parent327618831b73f65d4c91f125fe9cf03fecab3d2b (diff)
downloadscala-75e36233a0ea290cee98a35bc295feed4b18237e.tar.gz
scala-75e36233a0ea290cee98a35bc295feed4b18237e.tar.bz2
scala-75e36233a0ea290cee98a35bc295feed4b18237e.zip
SI-5314 - CPS transform of return statement fails
Enable return expressions in CPS code if they are in tail position. Note that tail returns are only removed in methods that do not call `shift` or `reset` (otherwise, an error is reported). Addresses the issues pointed out in a previous pull request: https://github.com/scala/scala/pull/720 - Addresses all issues mentioned here: https://github.com/scala/scala/pull/720#issuecomment-6429705 - Move transformation methods to SelectiveANFTransform.scala: https://github.com/scala/scala/pull/720#commitcomment-1477497 - Do not keep a list of tail returns. Tests: - continuations-neg/t5314-missing-result-type.scala - continuations-neg/t5314-type-error.scala - continuations-neg/t5314-npe.scala - continuations-neg/t5314-return-reset.scala - continuations-run/t5314.scala - continuations-run/t5314-2.scala - continuations-run/t5314-3.scala
Diffstat (limited to 'test/files/continuations-neg')
-rw-r--r--test/files/continuations-neg/t5314-missing-result-type.check4
-rw-r--r--test/files/continuations-neg/t5314-missing-result-type.scala13
-rw-r--r--test/files/continuations-neg/t5314-npe.check4
-rw-r--r--test/files/continuations-neg/t5314-npe.scala3
-rw-r--r--test/files/continuations-neg/t5314-return-reset.check4
-rw-r--r--test/files/continuations-neg/t5314-return-reset.scala21
-rw-r--r--test/files/continuations-neg/t5314-type-error.check6
-rw-r--r--test/files/continuations-neg/t5314-type-error.scala17
8 files changed, 72 insertions, 0 deletions
diff --git a/test/files/continuations-neg/t5314-missing-result-type.check b/test/files/continuations-neg/t5314-missing-result-type.check
new file mode 100644
index 0000000000..341e580cf3
--- /dev/null
+++ b/test/files/continuations-neg/t5314-missing-result-type.check
@@ -0,0 +1,4 @@
+t5314-missing-result-type.scala:6: error: method bar has return statement; needs result type
+ def bar(x:Int) = return foo(x)
+ ^
+one error found
diff --git a/test/files/continuations-neg/t5314-missing-result-type.scala b/test/files/continuations-neg/t5314-missing-result-type.scala
new file mode 100644
index 0000000000..d7c5043a86
--- /dev/null
+++ b/test/files/continuations-neg/t5314-missing-result-type.scala
@@ -0,0 +1,13 @@
+import scala.util.continuations._
+
+object Test extends App {
+ def foo(x:Int): Int @cps[Int] = x
+
+ def bar(x:Int) = return foo(x)
+
+ reset {
+ val res = bar(8)
+ println(res)
+ res
+ }
+}
diff --git a/test/files/continuations-neg/t5314-npe.check b/test/files/continuations-neg/t5314-npe.check
new file mode 100644
index 0000000000..b5f024aa89
--- /dev/null
+++ b/test/files/continuations-neg/t5314-npe.check
@@ -0,0 +1,4 @@
+t5314-npe.scala:2: error: method bar has return statement; needs result type
+ def bar(x:Int) = { return x; x } // NPE
+ ^
+one error found
diff --git a/test/files/continuations-neg/t5314-npe.scala b/test/files/continuations-neg/t5314-npe.scala
new file mode 100644
index 0000000000..2b5966e07c
--- /dev/null
+++ b/test/files/continuations-neg/t5314-npe.scala
@@ -0,0 +1,3 @@
+object Test extends App {
+ def bar(x:Int) = { return x; x } // NPE
+}
diff --git a/test/files/continuations-neg/t5314-return-reset.check b/test/files/continuations-neg/t5314-return-reset.check
new file mode 100644
index 0000000000..e288556546
--- /dev/null
+++ b/test/files/continuations-neg/t5314-return-reset.check
@@ -0,0 +1,4 @@
+t5314-return-reset.scala:14: error: return expressions not allowed, since method calls CPS method
+ if (rnd.nextInt(100) > 50) return 5 // not allowed, since method is calling `reset`
+ ^
+one error found
diff --git a/test/files/continuations-neg/t5314-return-reset.scala b/test/files/continuations-neg/t5314-return-reset.scala
new file mode 100644
index 0000000000..df9d58e4cb
--- /dev/null
+++ b/test/files/continuations-neg/t5314-return-reset.scala
@@ -0,0 +1,21 @@
+import scala.util.continuations._
+import scala.util.Random
+
+object Test extends App {
+ val rnd = new Random
+
+ def foo(x: Int): Int @cps[Int] = shift { k => k(x) }
+
+ def bar(x: Int): Int @cps[Int] = return foo(x)
+
+ def caller(): Int = {
+ val v: Int = reset {
+ val res: Int = bar(8)
+ if (rnd.nextInt(100) > 50) return 5 // not allowed, since method is calling `reset`
+ 42
+ }
+ v
+ }
+
+ caller()
+}
diff --git a/test/files/continuations-neg/t5314-type-error.check b/test/files/continuations-neg/t5314-type-error.check
new file mode 100644
index 0000000000..1f4e46a7f2
--- /dev/null
+++ b/test/files/continuations-neg/t5314-type-error.check
@@ -0,0 +1,6 @@
+t5314-type-error.scala:7: error: type mismatch;
+ found : Int @util.continuations.cps[Int]
+ required: Int @util.continuations.cps[String]
+ def bar(x:Int): Int @cps[String] = return foo(x)
+ ^
+one error found
diff --git a/test/files/continuations-neg/t5314-type-error.scala b/test/files/continuations-neg/t5314-type-error.scala
new file mode 100644
index 0000000000..e36ce6c203
--- /dev/null
+++ b/test/files/continuations-neg/t5314-type-error.scala
@@ -0,0 +1,17 @@
+import scala.util.continuations._
+
+object Test extends App {
+ def foo(x:Int): Int @cps[Int] = shift { k => k(x) }
+
+ // should be a type error
+ def bar(x:Int): Int @cps[String] = return foo(x)
+
+ def caller(): Unit = {
+ val v: String = reset {
+ val res: Int = bar(8)
+ "hello"
+ }
+ }
+
+ caller()
+}