diff options
author | Paul Phillips <paulp@improving.org> | 2013-05-12 10:57:42 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-05-12 10:57:42 -0700 |
commit | da91728a0b1d5e449eb13b697993d056e7ad53d6 (patch) | |
tree | 1961ede8e0f577d3f884322051c1dc21081c33e1 | |
parent | 7f29f8512d4975cf3a5a0b536a8910e4e3b4316b (diff) | |
parent | 15df9e970a1d1323148eee714352b55eba429f44 (diff) | |
download | scala-da91728a0b1d5e449eb13b697993d056e7ad53d6.tar.gz scala-da91728a0b1d5e449eb13b697993d056e7ad53d6.tar.bz2 scala-da91728a0b1d5e449eb13b697993d056e7ad53d6.zip |
Merge pull request #2501 from paulp/pr/tailcalls-tostring
Limit unnecessary calls to Type#toString.
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/TailCalls.scala | 12 | ||||
-rw-r--r-- | test/files/neg/tailrec-2.check | 2 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala index 9e867917f9..6f422fcc90 100644 --- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala +++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala @@ -89,12 +89,12 @@ abstract class TailCalls extends Transform { */ class TailCallElimination(unit: CompilationUnit) extends Transformer { private def defaultReason = "it contains a recursive call not in tail position" - private val failPositions = perRunCaches.newMap[TailContext, Position]() - private val failReasons = perRunCaches.newMap[TailContext, String]() + private val failPositions = perRunCaches.newMap[TailContext, Position]() withDefault (_.methodPos) + private val failReasons = perRunCaches.newMap[TailContext, String]() withDefaultValue defaultReason private def tailrecFailure(ctx: TailContext) { - val method = ctx.method - val failReason = failReasons.getOrElse(ctx, defaultReason) - val failPos = failPositions.getOrElse(ctx, ctx.methodPos) + val method = ctx.method + val failReason = failReasons(ctx) + val failPos = failPositions(ctx) unit.error(failPos, s"could not optimize @tailrec annotated $method: $failReason") } @@ -237,7 +237,7 @@ abstract class TailCalls extends Transform { if (!ctx.isEligible) fail("it is neither private nor final so can be overridden") else if (!isRecursiveCall) { - if (receiverIsSuper) failHere("it contains a recursive call targeting supertype " + receiver.tpe) + if (receiverIsSuper) failHere("it contains a recursive call targeting a supertype") else failHere(defaultReason) } else if (!matchesTypeArgs) failHere("it is called recursively with different type arguments") diff --git a/test/files/neg/tailrec-2.check b/test/files/neg/tailrec-2.check index d3432a7e76..1daad6922e 100644 --- a/test/files/neg/tailrec-2.check +++ b/test/files/neg/tailrec-2.check @@ -1,4 +1,4 @@ -tailrec-2.scala:8: error: could not optimize @tailrec annotated method f: it contains a recursive call targeting supertype Super[A] +tailrec-2.scala:8: error: could not optimize @tailrec annotated method f: it contains a recursive call targeting a supertype @annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = (null: Super[A]).f(mem) ^ tailrec-2.scala:9: error: @tailrec annotated method contains no recursive calls |