summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphaller <hallerp@gmail.com>2012-09-18 08:13:36 +0200
committerphaller <philipp.haller@typesafe.com>2012-10-30 12:05:41 +0100
commitb3d0a64218cdde3ad5f572cc817523208239aeaa (patch)
treef19bf88d0acbc0453971dcbc777690afe830adff
parent8aeae6231600a9bae14299bc92c8a6109c67c5af (diff)
downloadscala-b3d0a64218cdde3ad5f572cc817523208239aeaa.tar.gz
scala-b3d0a64218cdde3ad5f572cc817523208239aeaa.tar.bz2
scala-b3d0a64218cdde3ad5f572cc817523208239aeaa.zip
SI-6384 - avoid crash due to optimization in 2.10 CPS plugin
This fixes a regression in the 2.9.x branch (code combining CPS and try-catch crashing the compiler). The fix is simply undoing an optimization that was done in the 2.10 CPS plugin (replacing a function with only a match by a match on an empty tree).
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala7
-rw-r--r--test/files/continuations-run/trycatch3.check1
-rw-r--r--test/files/continuations-run/trycatch3.scala30
3 files changed, 37 insertions, 1 deletions
diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala
index a9900429ed..3cf0ce80ea 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala
@@ -191,14 +191,19 @@ abstract class SelectiveCPSTransform extends PluginComponent with
val pos = catches.head.pos
val funSym = currentOwner.newValueParameter(pos, cpsNames.catches).setInfo(appliedType(PartialFunctionClass.tpe, List(ThrowableClass.tpe, targettp)))
+ val argSym = currentOwner.newValueParameter(pos, cpsNames.ex).setInfo(ThrowableClass.tpe)
+ val rhs = Match(Ident(argSym), catches1)
+ val fun = Function(List(ValDef(argSym)), rhs)
val funDef = localTyper.typed(atPos(pos) {
- ValDef(funSym, Match(EmptyTree, catches1))
+ ValDef(funSym, fun)
})
val expr2 = localTyper.typed(atPos(pos) {
Apply(Select(expr1, expr1.tpe.member(cpsNames.flatMapCatch)), List(Ident(funSym)))
})
val exSym = currentOwner.newValueParameter(pos, cpsNames.ex).setInfo(ThrowableClass.tpe)
+ exSym.owner = fun.symbol
+ rhs.changeOwner(currentOwner -> fun.symbol)
import CODE._
// generate a case that is supported directly by the back-end
diff --git a/test/files/continuations-run/trycatch3.check b/test/files/continuations-run/trycatch3.check
new file mode 100644
index 0000000000..7ed6ff82de
--- /dev/null
+++ b/test/files/continuations-run/trycatch3.check
@@ -0,0 +1 @@
+5
diff --git a/test/files/continuations-run/trycatch3.scala b/test/files/continuations-run/trycatch3.scala
new file mode 100644
index 0000000000..c4bfb702de
--- /dev/null
+++ b/test/files/continuations-run/trycatch3.scala
@@ -0,0 +1,30 @@
+import scala.util.continuations._
+
+trait Result
+case class ValueResult(value: Int) extends Result
+case class ErrorResult(err: Exception) extends Result
+
+class Foo {
+ def func: Int @cpsParam[Any, Any] = shiftUnit[Int, Any, Any](5)
+}
+
+object Test extends App {
+ val foo = new Foo
+
+ def f: Result @cpsParam[Any, Any] = {
+ try {
+ //ValueResult(foo.func)
+ throw new Exception("" + foo.func)
+ }
+ catch {
+ case ex: Exception => ErrorResult(ex)
+ }
+ }
+
+ reset {
+ f match {
+ case ValueResult(x) => println(x)
+ case ErrorResult(ex) => println(ex.getMessage())
+ }
+ }
+}