Files
kotlin-fork/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/recursiveCallInInlineLambda.kt
T
Tianyu Geng 8525b4932b FIR Checker: check tailrec
Difference from FE1.0
* KT-4285: calls to virtual method with default argument should be
  reported as not tailrec. FE1.0 is missing such cases.
* KT-48600: calls inside lambda should be reported as not tailrec. FE1.0
  also misses such cases.
2021-09-14 23:48:50 +03:00

29 lines
599 B
Kotlin
Vendored

// KT-16549
// IGNORE_BACKEND: JVM
// IGNORE_FIR_DIAGNOSTICS_DIFF
class TailInline {
private inline fun act(action: () -> Unit) {
return action()
}
private var countDown = 10
tailrec fun test(): Int {
if (countDown < 5) return countDown
act {
countDown--
if (countDown < 1)
return countDown
else
return test() // GOTO countDown--
}
return countDown
}
}
fun box(): String {
val result = TailInline().test()
return if (result == 4) "OK" else "Fail: $result"
}