From 834a8faa123f168e8baea772b06ebce2874ff431 Mon Sep 17 00:00:00 2001 From: phaller Date: Sun, 12 Aug 2012 17:17:54 +0200 Subject: Simplify the adaptation of types of return expressions Add `adaptTypeOfReturn` hook to `AnnotationCheckers`. Move adaptation of types of return expressions from `addAnnotations` to `typedReturn` via `adaptTypeOfReturn` hook. This resolves an inconsistency where previously types could have a plus marker without additional CPS annotations. This also adds additional test cases. --- test/files/continuations-run/t5314-with-if.check | 1 + test/files/continuations-run/t5314-with-if.scala | 17 +++++++++++++++++ test/files/continuations-run/t5314.check | 4 ++++ test/files/continuations-run/t5314.scala | 11 +++++++++++ 4 files changed, 33 insertions(+) create mode 100644 test/files/continuations-run/t5314-with-if.check create mode 100644 test/files/continuations-run/t5314-with-if.scala (limited to 'test/files') diff --git a/test/files/continuations-run/t5314-with-if.check b/test/files/continuations-run/t5314-with-if.check new file mode 100644 index 0000000000..7f8f011eb7 --- /dev/null +++ b/test/files/continuations-run/t5314-with-if.check @@ -0,0 +1 @@ +7 diff --git a/test/files/continuations-run/t5314-with-if.scala b/test/files/continuations-run/t5314-with-if.scala new file mode 100644 index 0000000000..5840199a3c --- /dev/null +++ b/test/files/continuations-run/t5314-with-if.scala @@ -0,0 +1,17 @@ +import scala.util.continuations._ + +object Test extends App { + + def foo(x:Int): Int @cps[Int] = 7 + + def bar(x:Int): Int @cps[Int] = { + val v = foo(x) + if (v > 0) + return v + else + return 10 + } + + println(reset { bar(10) }) + +} diff --git a/test/files/continuations-run/t5314.check b/test/files/continuations-run/t5314.check index 4951e7caae..4b35d8e6d0 100644 --- a/test/files/continuations-run/t5314.check +++ b/test/files/continuations-run/t5314.check @@ -1,3 +1,7 @@ +7 +7 +7 +8 8 hi 8 diff --git a/test/files/continuations-run/t5314.scala b/test/files/continuations-run/t5314.scala index 0bdea19824..d611016ce4 100644 --- a/test/files/continuations-run/t5314.scala +++ b/test/files/continuations-run/t5314.scala @@ -29,6 +29,17 @@ object Test extends App { def nocps(x: Int): Int = { return x; x } + def foo2(x:Int): Int @cps[Int] = 7 + def bar2(x:Int): Int @cps[Int] = { foo2(x); return 7 } + def bar3(x:Int): Int @cps[Int] = { foo2(x); if (x == 7) return 7 else return foo2(x) } + def bar4(x:Int): Int @cps[Int] = { foo2(x); if (x == 7) return 7 else foo2(x) } + def bar5(x:Int): Int @cps[Int] = { foo2(x); if (x == 7) return 7 else 8 } + println(reset { bar2(10) }) + println(reset { bar3(10) }) + println(reset { bar4(10) }) + println(reset { bar5(10) }) + + /* original test case */ val repro = new ReturnRepro repro.caller repro.caller2 -- cgit v1.2.3