From b3d0a64218cdde3ad5f572cc817523208239aeaa Mon Sep 17 00:00:00 2001 From: phaller Date: Tue, 18 Sep 2012 08:13:36 +0200 Subject: 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). --- .../tools/selectivecps/SelectiveCPSTransform.scala | 7 ++++- test/files/continuations-run/trycatch3.check | 1 + test/files/continuations-run/trycatch3.scala | 30 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/files/continuations-run/trycatch3.check create mode 100644 test/files/continuations-run/trycatch3.scala 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()) + } + } +} -- cgit v1.2.3