diff options
author | Tiark Rompf <tiark.rompf@epfl.ch> | 2011-08-23 11:14:53 +0000 |
---|---|---|
committer | Tiark Rompf <tiark.rompf@epfl.ch> | 2011-08-23 11:14:53 +0000 |
commit | a93134b4832e95ff014f162f4cc8667f8136cb7d (patch) | |
tree | 384e33218c272f647d1fa1ad94e87b0d94c05768 | |
parent | 80952759fbaaf3a99f6bc0ca528da726b5a438e7 (diff) | |
download | scala-a93134b4832e95ff014f162f4cc8667f8136cb7d.tar.gz scala-a93134b4832e95ff014f162f4cc8667f8136cb7d.tar.bz2 scala-a93134b4832e95ff014f162f4cc8667f8136cb7d.zip |
applying patch provided by Topher, fixes #3501.
-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) + } + } +} |