object TestyFactorial:
// minimal example
import scala.annotation.tailrec
import language.experimental.saferExceptions
@tailrec
final def fact(n: Int, acc: Int): Int throws Exception =
if n < 0 then
throw new Exception
else if n == 0 then
acc
else
fact(n - 1, acc * n)
$sbt clean compile
...
[error] | fact(n - 1, acc * n)
[error] | ^^^^^^^^^^^^^^^^^^^^
[error] | Cannot rewrite recursive call: it is not in tail position
$head -1 build.sbt
ThisBuild / scalaVersion := "3.3.1-RC1-bin-20230322-1f574e8-NIGHTLY"
1 Like