summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2008-11-26 18:58:03 +0000
committerIulian Dragos <jaguarul@gmail.com>2008-11-26 18:58:03 +0000
commitb31dcbdcf503b96536ed4b538d5a3eb14431f785 (patch)
treea45e7e61e6d898c386c6b8e9fef111f539868522
parented4693400b490334a90490d3557198cb10e3d923 (diff)
downloadscala-b31dcbdcf503b96536ed4b538d5a3eb14431f785.tar.gz
scala-b31dcbdcf503b96536ed4b538d5a3eb14431f785.tar.bz2
scala-b31dcbdcf503b96536ed4b538d5a3eb14431f785.zip
Fixed 1541.
-rw-r--r--src/compiler/scala/tools/nsc/transform/TailCalls.scala8
-rw-r--r--test/files/run/tailcalls.check1
-rw-r--r--test/files/run/tailcalls.scala11
3 files changed, 18 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
index 3c174d9b97..582b632d32 100644
--- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala
+++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
@@ -253,8 +253,12 @@ abstract class TailCalls extends Transform
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))
+ 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
diff --git a/test/files/run/tailcalls.check b/test/files/run/tailcalls.check
index e913f2a061..7670962db2 100644
--- a/test/files/run/tailcalls.check
+++ b/test/files/run/tailcalls.check
@@ -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
diff --git a/test/files/run/tailcalls.scala b/test/files/run/tailcalls.scala
index 1340e8d532..73bc1427a3 100644
--- a/test/files/run/tailcalls.scala
+++ b/test/files/run/tailcalls.scala
@@ -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)
}
+
}
//############################################################################