Files
kotlin-fork/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/sum.kt
T
2016-11-09 21:41:12 +03:00

13 lines
335 B
Kotlin
Vendored

// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
tailrec fun sum(x: Long, sum: Long): Long {
if (x == 0.toLong()) return sum
return sum(x - 1, sum + x)
}
fun box() : String {
val sum = sum(1000000, 0)
if (sum != 500000500000.toLong()) return "Fail $sum"
return "OK"
}