mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-10 15:53:46 +00:00
Before 1.4 tailrec function default arguments were evaluated right-to-left instead of left-to-right. This is controlled by a compile-time flag. This change adds support for the right-to-left evaluation order when that flag is not set.
16 lines
389 B
Kotlin
Vendored
16 lines
389 B
Kotlin
Vendored
// !LANGUAGE: -ProperComputationOrderOfTailrecDefaultParameters
|
|
// TARGET_BACKEND: JVM
|
|
|
|
var counter = 0
|
|
fun calc(counter: Int) = if (counter % 2 == 0) "K" else "O"
|
|
|
|
<!TAILREC_WITH_DEFAULTS!>tailrec fun test(x: Int, y: String = calc(counter++), z: String = calc(counter++)): String<!> {
|
|
if (x > 0)
|
|
return y + z
|
|
|
|
return test(x + 1)
|
|
}
|
|
|
|
fun box(): String {
|
|
return test(0)
|
|
} |