Permalink
Browse files

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).
  • Loading branch information...
1 parent 8aeae62 commit b3d0a64218cdde3ad5f572cc817523208239aeaa @phaller phaller committed Sep 18, 2012
@@ -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
@@ -0,0 +1 @@
+5
@@ -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())
+ }
+ }
+}

0 comments on commit b3d0a64

Please sign in to comment.