Fixed 1541.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@16654 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
dragos 2008-11-26 18:58:03 +00:00
parent 1e9d5dbcb9
commit a448b61cbc
3 changed files with 19 additions and 3 deletions

View File

@ -252,9 +252,13 @@ abstract class TailCalls extends Transform
isSameTypes(ctx.tparams, targs map (_.tpe.typeSymbol)) &&
isRecursiveCall(fun)) {
fun match {
case Select(receiver, _) =>
// make sure the type of 'this' doesn't change through this recursive call
if (!forMSIL && (receiver.tpe.widen == ctx.currentMethod.enclClass.typeOfThis))
case Select(receiver, _) =>
val recTpe = receiver.tpe.widen
val enclTpe = ctx.currentMethod.enclClass.typeOfThis
// make sure the type of 'this' doesn't change through this polymorphic recursive call
if (!forMSIL &&
(receiver.tpe.typeParams.isEmpty ||
(receiver.tpe.widen == ctx.currentMethod.enclClass.typeOfThis)))
rewriteTailCall(fun, receiver :: transformTrees(vargs, mkContext(ctx, false)))
else
defaultTree

View File

@ -51,3 +51,4 @@ test TailCall.b1 was successful
test TailCall.b2 was successful
test FancyTailCalls.tcTryLocal was successful
test FancyTailCalls.differentInstance was successful
test PolyObject.tramp was successful

View File

@ -194,6 +194,15 @@ object FancyTailCalls {
val f2 = new FancyTailCalls
}
object PolyObject extends Application {
def tramp[A](x: Int): Int =
if (x > 0)
tramp[A](x - 1)
else
0
}
class FancyTailCalls {
def tcTryLocal(x: Int, v: Int): Int = {
@ -370,7 +379,9 @@ object Test {
val FancyTailCalls = new FancyTailCalls;
check_success("FancyTailCalls.tcTryLocal", FancyTailCalls.tcTryLocal(max, max), max)
check_success("FancyTailCalls.differentInstance", FancyTailCalls.differentInstance(max, 42), 42)
check_success("PolyObject.tramp", PolyObject.tramp[Int](max), 0)
}
}
//############################################################################