Skip to content

Commit 133fbb3

Browse files
authored
Merge pull request #1620 from dotty-staging/fix-1614
Fix #1614 tailrec.
2 parents 56731e4 + 20cbcca commit 133fbb3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/dotty/tools/dotc/transform/TailRec.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
143143
newOwners = label :: Nil
144144
).transform(rhsSemiTransformed)
145145
})
146-
Block(List(labelDef), ref(label).appliedToArgss(vparamss0.map(_.map(x=> ref(x.symbol)))))
146+
val callIntoLabel = (
147+
if (dd.tparams.isEmpty) ref(label)
148+
else ref(label).appliedToTypes(dd.tparams.map(_.tpe))
149+
).appliedToArgss(vparamss0.map(_.map(x=> ref(x.symbol))))
150+
Block(List(labelDef), callIntoLabel)
147151
}} else {
148152
if (mandatory) ctx.error(
149153
"TailRec optimisation not applicable, method not tail recursive",

tests/pos/tailcall/i1614.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Foobar {
2+
def apply(): Option[String] = {
3+
def foobar[A](f: (String, String) => A): List[A] = List[String]() match {
4+
case _ :: ls => foobar(f)
5+
}
6+
foobar((a1, a2) => (a1 + a2)).headOption
7+
}
8+
}
9+

0 commit comments

Comments
 (0)