【发布时间】:2017-10-04 20:41:29
【问题描述】:
这是引发编译错误“递归调用不在尾部位置”的最小代码。但是,我使用的是@inline,递归调用 is 在尾部位置。我使用这个@inline 的原因是我将原始reccall 的代码复制了两次。
import scala.annotation._
object Test {
@tailrec private def test(i: Int): Int = {
@inline def reccall(i: Int): Int = test(i-1)
i match {
case 0 => 0
case i => reccall(i)
}
}
}
我查看了Recursive call not in tail position@tailrec why does this method not compile with 'contains a recursive call not in tail position'? 的答案,但它们不适用于我的情况。使用 Scala 2.12
【问题讨论】:
标签: scala inline tail-recursion