diff options
-rw-r--r-- | src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala | 5 | ||||
-rw-r--r-- | test/files/continuations-run/t3501.check | 5 | ||||
-rw-r--r-- | test/files/continuations-run/t3501.scala | 15 |
3 files changed, 24 insertions, 1 deletions
diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala index 001a1b4b62..8889b75770 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala @@ -211,12 +211,13 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with case ldef @ LabelDef(name, params, rhs) => if (hasAnswerTypeAnn(tree.tpe)) { - val sym = currentOwner.newMethod(tree.pos, name)//unit.fresh.newName(tree.pos, "myloopvar") + val sym = currentOwner.newMethod(tree.pos, name) .setInfo(ldef.symbol.info) .setFlag(Flags.SYNTHETIC) val rhs1 = new TreeSymSubstituter(List(ldef.symbol), List(sym)).transform(rhs) val rhsVal = transExpr(rhs1, None, getAnswerTypeAnn(tree.tpe)) + new ChangeOwnerTraverser(currentOwner, sym) traverse rhsVal val stm1 = localTyper.typed(DefDef(sym, rhsVal)) val expr = localTyper.typed(Apply(Ident(sym), List())) @@ -355,6 +356,8 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with .setFlag(Flags.SYNTHETIC) .setAnnotations(List(AnnotationInfo(MarkerCPSSym.tpe, Nil, Nil))) + new ChangeOwnerTraverser(currentOwner, sym) traverse expr + (stms ::: List(ValDef(sym, expr) setType(NoType)), Ident(sym) setType(valueTpe) setPos(tree.pos), linearize(spc, spcVal)(unit, tree.pos)) diff --git a/test/files/continuations-run/t3501.check b/test/files/continuations-run/t3501.check new file mode 100644 index 0000000000..08adcfe27a --- /dev/null +++ b/test/files/continuations-run/t3501.check @@ -0,0 +1,5 @@ +42 +42 +42 +42 +42 diff --git a/test/files/continuations-run/t3501.scala b/test/files/continuations-run/t3501.scala new file mode 100644 index 0000000000..c43b3322be --- /dev/null +++ b/test/files/continuations-run/t3501.scala @@ -0,0 +1,15 @@ +import scala.util.continuations._ + +object Test { + def capture(): Int @suspendable = 42 + + def main(args: Array[String]): Unit = reset { + var i = 0 + while (i < 5) { + i += 1 + val y = capture() + val s = y + println(s) + } + } +} |