diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-10-25 15:22:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-25 15:22:32 +0200 |
commit | 133fbb352b5acafb9e1ea5ab53e8678dca03afd9 (patch) | |
tree | 27d5ad39e133aac6431f8c463446cb1ae373876e | |
parent | 56731e4b18728427f0b7188eb91afc475b36bb18 (diff) | |
parent | 20cbcca0ec49a3d4de1021d261cc4a35d242925b (diff) | |
download | dotty-133fbb352b5acafb9e1ea5ab53e8678dca03afd9.tar.gz dotty-133fbb352b5acafb9e1ea5ab53e8678dca03afd9.tar.bz2 dotty-133fbb352b5acafb9e1ea5ab53e8678dca03afd9.zip |
Merge pull request #1620 from dotty-staging/fix-1614
Fix #1614 tailrec.
-rw-r--r-- | src/dotty/tools/dotc/transform/TailRec.scala | 6 | ||||
-rw-r--r-- | tests/pos/tailcall/i1614.scala | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/transform/TailRec.scala b/src/dotty/tools/dotc/transform/TailRec.scala index d99a48af3..fde4db811 100644 --- a/src/dotty/tools/dotc/transform/TailRec.scala +++ b/src/dotty/tools/dotc/transform/TailRec.scala @@ -143,7 +143,11 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete newOwners = label :: Nil ).transform(rhsSemiTransformed) }) - Block(List(labelDef), ref(label).appliedToArgss(vparamss0.map(_.map(x=> ref(x.symbol))))) + val callIntoLabel = ( + if (dd.tparams.isEmpty) ref(label) + else ref(label).appliedToTypes(dd.tparams.map(_.tpe)) + ).appliedToArgss(vparamss0.map(_.map(x=> ref(x.symbol)))) + Block(List(labelDef), callIntoLabel) }} else { if (mandatory) ctx.error( "TailRec optimisation not applicable, method not tail recursive", diff --git a/tests/pos/tailcall/i1614.scala b/tests/pos/tailcall/i1614.scala new file mode 100644 index 000000000..4c10e963d --- /dev/null +++ b/tests/pos/tailcall/i1614.scala @@ -0,0 +1,9 @@ +object Foobar { + def apply(): Option[String] = { + def foobar[A](f: (String, String) => A): List[A] = List[String]() match { + case _ :: ls => foobar(f) + } + foobar((a1, a2) => (a1 + a2)).headOption + } +} + |