diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2016-03-31 14:27:30 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2016-03-31 14:50:36 +0200 |
commit | aab561c46144f2d9510ba881bf8dc0549631292a (patch) | |
tree | 9d4516e4c6c0062d021a5853d5d060bfb97e38e4 /src | |
parent | 07833e93f62cbe6d866300475288e8a763a36198 (diff) | |
download | dotty-aab561c46144f2d9510ba881bf8dc0549631292a.tar.gz dotty-aab561c46144f2d9510ba881bf8dc0549631292a.tar.bz2 dotty-aab561c46144f2d9510ba881bf8dc0549631292a.zip |
Tailrec: drop support for polymorphic recursion.
If the method that recurses over a different type arguments,
if this method is specialised, it would lead to method not
being tail-rec anymore.
Eg:
def foo[@specialized A, @specialized B]: Unit = foo[B, A]
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/transform/TailRec.scala | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/transform/TailRec.scala b/src/dotty/tools/dotc/transform/TailRec.scala index 558206960..1f6a32035 100644 --- a/src/dotty/tools/dotc/transform/TailRec.scala +++ b/src/dotty/tools/dotc/transform/TailRec.scala @@ -176,6 +176,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete } val (prefix, call, arguments, typeArguments, symbol) = receiverArgumentsAndSymbol(tree) + val hasConformingTargs = (typeArguments zip methTparams).forall{x => x._1.tpe <:< x._2.tpe} val recv = noTailTransform(prefix) val targs = typeArguments.map(noTailTransform) @@ -228,7 +229,8 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete if (isRecursiveCall) { if (ctx.tailPos) { - if (recv eq EmptyTree) rewriteTailCall(This(enclosingClass.asClass)) + if (!hasConformingTargs) fail("it changes type arguments on a polymorphic recursive call") + else if (recv eq EmptyTree) rewriteTailCall(This(enclosingClass.asClass)) else if (receiverIsSame || receiverIsThis) rewriteTailCall(recv) else fail("it changes type of 'this' on a polymorphic recursive call") } |