natpryce
12/20/2016, 8:49 AMclass Example(val parent: Example?) {
// This is tail recursive
tailrec fun foo(e: Example) {
if (e.parent != null) foo(e.parent)
}
// But this is not and causes a compiler warning: "Recursive call is not a tail call"
tailrec fun foo() {
if (parent != null) parent.foo()
}
}
Given that the class is closed and the call to foo
not polymorphic, I’d have thought that there would be no difference between passing parent
to the recursive call as an explicit parameter or the implicit this
reference.
Am I missing something?
If not, could tail recursive, non-polymorphic instance methods be supported in a future language version?