Let's say I define the following function:
final def myFunc[T](list: List[T]): List[T] = list match {
case h :: t =>
h :: myFunc(t)
case _ =>
Nil
}
When I add tailrec annotation, the compiler gives me the following error:
failed to optimize @tailrec annotated myFunc method: it contains a recursive call not in tail position: ^ Nil.
I am confused by how a Nil declaration can be a recursive call?
source
share