summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphaller <hallerp@gmail.com>2012-08-09 14:50:30 +0200
committerphaller <hallerp@gmail.com>2012-11-02 18:36:52 +0100
commite566ab3702cbd89988191a9d86b756b78a534dd3 (patch)
treebd362946b53acc5e11ee9eec9b4ceb161ac4498b
parent4c5aa9badf1e67e83cc5ea393611dad4a2edb60e (diff)
downloadscala-e566ab3702cbd89988191a9d86b756b78a534dd3.tar.gz
scala-e566ab3702cbd89988191a9d86b756b78a534dd3.tar.bz2
scala-e566ab3702cbd89988191a9d86b756b78a534dd3.zip
Add missing cases in tail return transform
Disabled warnings that no longer apply because of tail returns. Add several test cases.
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala9
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala10
-rw-r--r--test/files/continuations-run/t5314.check4
-rw-r--r--test/files/continuations-run/t5314.scala11
4 files changed, 26 insertions, 8 deletions
diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala
index 545172d407..a6d4cf45d7 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala
@@ -169,13 +169,8 @@ trait CPSUtils {
// anf transform
- def getExternalAnswerTypeAnn(tp: Type) = {
- cpsParamTypes(tp) orElse {
- if (hasPlusMarker(tp))
- global.warning("trying to instantiate type " + tp + " to unknown cps type")
- None
- }
- }
+ def getExternalAnswerTypeAnn(tp: Type) =
+ cpsParamTypes(tp) orElse None
def getAnswerTypeAnn(tp: Type): Option[(Type, Type)] =
cpsParamTypes(tp) filterNot (_ => hasPlusMarker(tp))
diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala
index 8ab9ba881f..b789bc7716 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala
@@ -43,6 +43,12 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
case If(cond, r1 @ Return(thenExpr), r2 @ Return(elseExpr)) =>
treeCopy.If(tree, cond, transform(thenExpr), transform(elseExpr))
+ case If(cond, r1 @ Return(thenExpr), elseExpr) =>
+ treeCopy.If(tree, cond, transform(thenExpr), transform(elseExpr))
+
+ case If(cond, thenExpr, r2 @ Return(elseExpr)) =>
+ treeCopy.If(tree, cond, transform(thenExpr), transform(elseExpr))
+
case If(cond, thenExpr, elseExpr) =>
treeCopy.If(tree, cond, transform(thenExpr), transform(elseExpr))
@@ -440,7 +446,9 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
// all is well
if (hasPlusMarker(expr.tpe)) {
- unit.warning(tree.pos, "expression " + expr + " of type " + expr.tpe + " is not expected to have a cps type")
+ // the following warning no longer applies, since expr may have originated from a tail return expr
+ // note that it would be illegal to remove the plus marker (thus disabling required transformations)
+ //unit.warning(tree.pos, "expression " + expr + " of type " + expr.tpe + " is not expected to have a cps type")
expr modifyType removeAllCPSAnnotations
}
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