Why are non-tail-recursive functions marked with `...
# language-evolution
c
Why are non-tail-recursive functions marked with
tailrec
only a warning and not an error?
y
Because the tail recursion can still apply to the valid tail calls.
c
🤔
So if there are 3 returns, and 2 are tailrec, the function will be able to tailrec on these two?
y
Exactly!
c
Thanks! I didn't know that was possible, interesting
Then, why isn't it an error when no return is tailrec?
âž• 1
j
Yeah I'm also wondering. Whether the tail recursion can be unrolled is statically known at compile time, so the compiler should be able to tell when
tailrec
doesn't apply at all. It could be an error, then
e
I'm not sure if
tailrec
affects the calling ABI on any platform… on JVM it doesn't, but if it did, then that would be a reason to allow no-op
tailrec
, so that a function that was formerly
tailrec
and changed implementation would not be broken. (the other way around could be handled with a wrapper function)
it does feel like it should at least be a warning though