rgrasell
08/10/2018, 2:00 PMthis
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:
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)
}