I'm seeing these warnings for this class: ```> ...
# compiler
r
I'm seeing these warnings for this class:
Copy code
> 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.
Copy code
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
}
If I desugar the elvis operator the warnings go away:
Copy code
package 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
}
That seems wrong?
Kotlin 2.1.20
d
It's fixed in 2.2.20-Beta2: KT-73420
r
Thanks