diff options
author | phaller <hallerp@gmail.com> | 2012-07-23 14:03:22 +0200 |
---|---|---|
committer | phaller <hallerp@gmail.com> | 2012-08-08 16:24:29 +0200 |
commit | 75e36233a0ea290cee98a35bc295feed4b18237e (patch) | |
tree | a8950fa574a01f410765df6d1eda0ed918a8f4da /test/files/continuations-run/t5314-3.scala | |
parent | 327618831b73f65d4c91f125fe9cf03fecab3d2b (diff) | |
download | scala-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-run/t5314-3.scala')
-rw-r--r-- | test/files/continuations-run/t5314-3.scala | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/files/continuations-run/t5314-3.scala b/test/files/continuations-run/t5314-3.scala new file mode 100644 index 0000000000..62c547f5a2 --- /dev/null +++ b/test/files/continuations-run/t5314-3.scala @@ -0,0 +1,27 @@ +import scala.util.continuations._ + +class ReturnRepro { + def s1: Int @cpsParam[Any, Unit] = shift { k => k(5) } + def caller = reset { println(p(3)) } + def caller2 = reset { println(p2(3)) } + + def p(i: Int): Int @cpsParam[Unit, Any] = { + val v= s1 + 3 + return { println("enter return expr"); v } + } + + def p2(i: Int): Int @cpsParam[Unit, Any] = { + val v = s1 + 3 + if (v > 0) { + return { println("hi"); v } + } else { + return { println("hi"); 8 } + } + } +} + +object Test extends App { + val repro = new ReturnRepro + repro.caller + repro.caller2 +} |