Is there any reason that a tail recursive function...
# announcements
r
Is there any reason that a tail recursive function call on a non-
this
receiver would be considered not
tailrec
by the Kotlin compiler? The same function can be called on
this
as the receiver or be reimplemented by moving the receiver to a parameter to be handled correctly. For example:
Copy code
class RecTest {
    val otherInstance = RecTest()

    // Compiler and IntelliJ complain that this isn't tail recursive
    tailrec fun differentReceiver() {
        return otherInstance.differentReceiver()
    }

    // Correctly processed as tail recursive
    tailrec fun thisReceiver() {
        return this.thisReceiver()
    }
}

// Correctly processed as tail recursive
tailrec fun noReceiver(recTest: RecTest) {
    return noReceiver(recTest.otherInstance)
}
youtrack 3