backend/tests: Add blackbox tests from Kotlin JVM

Added tests from testData/codegen/box directory. There are blackbox tests
in other directories and they are to be added.
This commit is contained in:
Ilya Matveev
2017-01-12 19:43:20 +07:00
parent d5988297b1
commit 1b553ebfaf
2643 changed files with 66666 additions and 0 deletions
@@ -0,0 +1,15 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun test(x : Int = 0, e : Any = "a") {
if (!e.equals("a")) {
throw IllegalArgumentException()
}
if (x > 0) {
test(x - 1)
}
}
fun box() : String {
test(100000)
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ x: kotlin.Int = ..., /*1*/ e: kotlin.Any = ...): kotlin.Unit
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
open class A {
open fun foo(s: String = "OK") = s
}
class B : A() {
<!NO_TAIL_CALLS_FOUND!>override tailrec fun foo(s: String): String<!> {
return if (s == "OK") s else foo()
}
}
fun box() = B().foo("FAIL")
@@ -0,0 +1,19 @@
package
public fun box(): kotlin.String
public open class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun foo(/*0*/ s: kotlin.String = ...): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class B : A {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open tailrec override /*1*/ fun foo(/*0*/ s: kotlin.String = ...): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun Int.foo(x: Int) {
if (x == 0) return
return 1.foo(x - 1)
}
fun box(): String {
1.foo(1000000)
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun kotlin.Int.foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -0,0 +1,11 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
<!NO_TAIL_CALLS_FOUND!>tailrec fun noTails()<!> {
// nothing here
}
fun box(): String {
noTails()
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun noTails(): kotlin.Unit
@@ -0,0 +1,20 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun badTails(x : Int) : Int {
if (x < 50 && x != 10 && x > 0) {
return 1 + <!NON_TAIL_RECURSIVE_CALL!>badTails<!>(x - 1)
}
else if (x == 10) {
@Suppress("NON_TAIL_RECURSIVE_CALL")
return 1 + badTails(x - 1)
} else if (x >= 50) {
return badTails(x - 1)
}
return 0
}
fun box(): String {
badTails(1000000)
return "OK"
}
@@ -0,0 +1,4 @@
package
public tailrec fun badTails(/*0*/ x: kotlin.Int): kotlin.Int
public fun box(): kotlin.String
@@ -0,0 +1,14 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
fun withoutAnnotation(x : Int) : Int {
if (x > 0) {
return 1 + withoutAnnotation(x - 1)
}
return 0
}
fun box(): String {
val r = withoutAnnotation(10)
if (r == 10) return "OK"
return "Fail $r"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public fun withoutAnnotation(/*0*/ x: kotlin.Int): kotlin.Int
@@ -0,0 +1,10 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec infix fun Int.test(x : Int) : Int {
if (this > 1) {
return (this - 1) test x
}
return this
}
fun box() : String = if (1000000.test(1000000) == 1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public infix tailrec fun kotlin.Int.test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -0,0 +1,14 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec infix fun Int.foo(x: Int) {
if (x == 0) return
val xx = x - 1
return 1 foo xx
}
fun box(): String {
1 foo 1000000
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public infix tailrec fun kotlin.Int.foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -0,0 +1,13 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun test(counter : Int) : Int? {
if (counter < 0) return null
if (counter == 0) return 777
return <!NON_TAIL_RECURSIVE_CALL!>test<!>(-1) ?: <!NON_TAIL_RECURSIVE_CALL!>test<!>(-2) ?: test(counter - 1)
}
fun box() : String =
if (test(100000) == 777) "OK"
else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ counter: kotlin.Int): kotlin.Int?
@@ -0,0 +1,30 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
class B {
inner class C {
tailrec fun h(counter : Int) {
if (counter > 0) {
this@C.h(counter - 1)
}
}
<!NO_TAIL_CALLS_FOUND!>tailrec fun h2(x : Any)<!> {
this@B.h2("no recursion") // keep vigilance
}
}
fun makeC() : C = C()
fun h2(x : Any) {
}
}
fun box() : String {
B().makeC().h(1000000)
B().makeC().h2(0)
return "OK"
}
@@ -0,0 +1,21 @@
package
public fun box(): kotlin.String
public final class B {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun h2(/*0*/ x: kotlin.Any): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun makeC(): B.C
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final inner class C {
public constructor C()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final tailrec fun h(/*0*/ counter: kotlin.Int): kotlin.Unit
public final tailrec fun h2(/*0*/ x: kotlin.Any): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -0,0 +1,17 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun test(x : Int) : Int {
var z = if (x > 3) 3 else x
while (z > 0) {
if (z > 10) {
return test(x - 1)
}
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0)
z = z - 1
}
return 1
}
fun box() : String = if (test(100000) == 1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -0,0 +1,18 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun test(x : Int) : Int {
if (x == 1) {
if (x != 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0)
return test(0)
} else {
return test(x + <!NON_TAIL_RECURSIVE_CALL!>test<!>(0))
}
} else if (x > 0) {
return test(x - 1)
}
return -1
}
fun box() : String = if (test(1000000) == -1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun <T, A> Iterator<T>.foldl(acc : A, foldFunction : (e : T, acc : A) -> A) : A =
if (!hasNext()) acc
else foldl(foldFunction(next(), acc), foldFunction)
fun box() : String {
val sum = (1..1000000).iterator().foldl(0) { e : Int, acc : Long ->
acc + e
}
return if (sum == 500000500000) "OK" else "FAIL: $sum"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun </*0*/ T, /*1*/ A> kotlin.collections.Iterator<T>.foldl(/*0*/ acc: A, /*1*/ foldFunction: (e: T, acc: A) -> A): A
@@ -0,0 +1,17 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
fun escapeChar(c : Char) : String? = when (c) {
'\\' -> "\\\\"
'\n' -> "\\n"
'"' -> "\\\""
else -> "" + c
}
tailrec fun String.escape(i : Int = 0, result : StringBuilder = StringBuilder()) : String =
if (i == length) result.toString()
else escape(i + 1, result.append(escapeChar(get(i))))
fun box() : String {
"test me not \\".escape()
return "OK"
}
@@ -0,0 +1,5 @@
package
public fun box(): kotlin.String
public fun escapeChar(/*0*/ c: kotlin.Char): kotlin.String?
public tailrec fun kotlin.String.escape(/*0*/ i: kotlin.Int = ..., /*1*/ result: kotlin.text.StringBuilder /* = java.lang.StringBuilder */ = ...): kotlin.String
@@ -0,0 +1,10 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun String.repeat(num : Int, acc : StringBuilder = StringBuilder()) : String =
if (num == 0) acc.toString()
else repeat(num - 1, acc.append(this))
fun box() : String {
val s = "a".repeat(10000)
return if (s.length == 10000) "OK" else "FAIL: ${s.length}"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun kotlin.String.repeat(/*0*/ num: kotlin.Int, /*1*/ acc: kotlin.text.StringBuilder /* = java.lang.StringBuilder */ = ...): kotlin.String
@@ -0,0 +1,17 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
<!NO_TAIL_CALLS_FOUND!>tailrec fun foo()<!> {
bar {
<!NON_TAIL_RECURSIVE_CALL!>foo<!>()
}
}
fun bar(a: Any) {}
fun box(): String {
foo()
return "OK"
}
@@ -0,0 +1,5 @@
package
public fun bar(/*0*/ a: kotlin.Any): kotlin.Unit
public fun box(): kotlin.String
public tailrec fun foo(): kotlin.Unit
@@ -0,0 +1,13 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
<!NO_TAIL_CALLS_FOUND!>tailrec fun foo()<!> {
fun bar() {
<!NON_TAIL_RECURSIVE_CALL!>foo<!>()
}
}
fun box(): String {
foo()
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun foo(): kotlin.Unit
@@ -0,0 +1,13 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
fun test() {
tailrec fun g3(counter : Int) {
if (counter > 0) { g3(counter - 1) }
}
g3(1000000)
}
fun box() : String {
test()
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public fun test(): kotlin.Unit
@@ -0,0 +1,15 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun test(x : Int) : Int {
return if (x == 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
} else if (x > 0) {
test(x - 1)
} else {
0
}
}
fun box() : String = if (test(1000000) == 1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
throw Exception()
} catch (e : Exception) {
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1)
}
}
fun box() : String = if (test(3) == 0) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
// do nothing
} finally {
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1)
}
}
fun box() : String = if (test(3) == 0) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -0,0 +1,18 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
// do nothing
} finally {
if (counter > 0) {
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1)
}
}
return -1
}
fun box() : String = if (test(3) == 0) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -0,0 +1,11 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun foo(x: Int) {
if (x == 0) return
(return foo(x - 1))
}
fun box(): String {
foo(1000000)
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(counter : Int) : Int<!> {
if (counter == 0) return 0
try {
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1)
} catch (any : Throwable) {
return -1
}
}
fun box() : String = if (test(3) == 0) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun test(x : Int) : Int =
if (x == 1) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
} else if (x > 0) {
test(x - 1)
} else {
0
}
fun box() : String = if (test(1000000) == 1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -0,0 +1,14 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun test(x : Int) : Int {
if (x == 10) {
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
}
if (x > 0) {
return test(x - 1)
}
return 0
}
fun box() : String = if (test(1000000) == 1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -0,0 +1,15 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun test(x : Int) : Int {
if (x == 0) {
return 0
} else if (x == 10) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0)
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
} else {
return test(x - 1)
}
}
fun box() : String = if (test(1000000) == 1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ x: kotlin.Int): kotlin.Int
@@ -0,0 +1,13 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: 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"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun sum(/*0*/ x: kotlin.Long, /*1*/ sum: kotlin.Long): kotlin.Long
@@ -0,0 +1,13 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun foo(x: Int) {
return if (x > 0) {
(foo(x - 1))
}
else Unit
}
fun box(): String {
foo(1000000)
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -0,0 +1,11 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun foo(x: Int) {
if (x == 0) return
return (foo(x - 1))
}
fun box(): String {
foo(1000000)
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -0,0 +1,18 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
<!NO_TAIL_CALLS_FOUND!>tailrec fun test(go: Boolean) : Unit<!> {
if (!go) return
try {
<!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(false)
} catch (any : Exception) {
<!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(false)
} finally {
<!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(false)
}
}
fun box(): String {
test(true)
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ go: kotlin.Boolean): kotlin.Unit
@@ -0,0 +1,26 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
class A {
tailrec fun f1(c : Int) {
if (c > 0) {
this.f1(c - 1)
}
}
tailrec fun f2(c : Int) {
if (c > 0) {
f2(c - 1)
}
}
<!NO_TAIL_CALLS_FOUND!>tailrec fun f3(a : A)<!> {
a.<!NON_TAIL_RECURSIVE_CALL!>f3<!>(a) // non-tail recursion, could be potentially resolved by condition if (a == this) f3() else a.f3()
}
}
fun box() : String {
A().f1(1000000)
A().f2(1000000)
return "OK"
}
@@ -0,0 +1,13 @@
package
public fun box(): kotlin.String
public final class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final tailrec fun f1(/*0*/ c: kotlin.Int): kotlin.Unit
public final tailrec fun f2(/*0*/ c: kotlin.Int): kotlin.Unit
public final tailrec fun f3(/*0*/ a: A): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,24 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun test(x : Int) : Unit {
if (x == 1) {
test(x - 1)
} else if (x == 2) {
test(x - 1)
return
} else if (x == 3) {
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1)
if (x == 3) {
test(x - 1)
}
return
} else if (x > 0) {
test(x - 1)
}
}
fun box() : String {
test(1000000)
return "OK"
}
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun test(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -0,0 +1,11 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun withWhen(counter : Int) : Int =
when (counter) {
0 -> counter
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1)
else -> withWhen(counter - 1)
}
fun box() : String = if (withWhen(100000) == 1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun withWhen(/*0*/ counter: kotlin.Int): kotlin.Int
@@ -0,0 +1,16 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun withWhen(counter : Int, d : Any) : Int =
when (counter) {
0 -> counter
1, 2 -> withWhen(counter - 1, "1,2")
in 3..49 -> withWhen(counter - 1, "3..49")
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1, "50")
!in 0..50 -> withWhen(counter - 1, "!0..50")
else -> withWhen(counter - 1, "else")
}
fun box() : String = if (withWhen(100000, "test") == 1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun withWhen(/*0*/ counter: kotlin.Int, /*1*/ d: kotlin.Any): kotlin.Int
@@ -0,0 +1,17 @@
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun withWhen(counter : Int, d : Any) : Int =
if (counter == 0) {
0
}
else if (counter == 5) {
withWhen(counter - 1, 999)
}
else
when (d) {
is String -> withWhen(counter - 1, "is String")
is Number -> withWhen(counter, "is Number")
else -> throw IllegalStateException()
}
fun box() : String = if (withWhen(100000, "test") == 0) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun withWhen(/*0*/ counter: kotlin.Int, /*1*/ d: kotlin.Any): kotlin.Int
@@ -0,0 +1,12 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec fun withWhen2(counter : Int) : Int =
when {
counter == 0 -> counter
counter == 50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(counter - 1)
<!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(0) == 0 -> withWhen2(counter - 1)
else -> 1
}
fun box() : String = if (withWhen2(100000) == 1) "OK" else "FAIL"
@@ -0,0 +1,4 @@
package
public fun box(): kotlin.String
public tailrec fun withWhen2(/*0*/ counter: kotlin.Int): kotlin.Int