Rob Elliot
04/02/2025, 3:03 PM> Task :core:compileKotlin
w: file:///Users/me/dev/mylib/core/src/main/kotlin/Test.kt:5:11 A function is marked as tail-recursive but no tail calls are found.
w: file:///Users/me/dev/mylib/core/src/main/kotlin/Test.kt:8:25 Recursive call is not a tail call.
w: file:///Users/me/dev/mylib/core/src/main/kotlin/Test.kt:9:25 Recursive call is not a tail call.
package foo
class Test {
private tailrec fun recursiveInWhen(): Int? {
val decision: Int = 2
return when (decision) {
1 -> handle1() ?: recursiveInWhen()
2 -> handle2() ?: recursiveInWhen()
else -> null
}
}
private fun handle1(): Int? = null
private fun handle2(): Int? = null
}
Rob Elliot
04/02/2025, 3:04 PMpackage foo
class Test {
private tailrec fun recursiveInWhen(): Int? {
val decision: Int = 2
return when (decision) {
1 -> {
val handle1 = handle1()
if (handle1 != null) handle1 else recursiveInWhen()
}
2 -> {
val handle2 = handle2()
if (handle2 != null) handle2 else recursiveInWhen()
}
else -> null
}
}
private fun handle1(): Int? = null
private fun handle2(): Int? = null
}
Rob Elliot
04/02/2025, 3:04 PMRob Elliot
04/02/2025, 3:05 PMdmitriy.novozhilov
04/02/2025, 3:05 PMRob Elliot
04/02/2025, 3:05 PM