Use codegen box tests for tail calls as diagnostic tests too
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun test(counter : Int, a : Any) : Int? {
|
||||
if (counter < 0) return null
|
||||
if (counter == 0) return 777
|
||||
|
||||
return test(-1, "no tail") ?: test(-2, "no tail") ?: test(counter - 1, "tail")
|
||||
return <!NON_TAIL_RECURSIVE_CALL!>test<!>(-1, "no tail") ?: <!NON_TAIL_RECURSIVE_CALL!>test<!>(-2, "no tail") ?: test(counter - 1, "tail")
|
||||
}
|
||||
|
||||
fun box() : String =
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class B {
|
||||
inner class C {
|
||||
tailRecursive fun h(counter : Int, x : Any) {
|
||||
@@ -6,7 +8,7 @@ class B {
|
||||
}
|
||||
}
|
||||
|
||||
tailRecursive fun h2(x : Any) {
|
||||
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun h2(x : Any)<!> {
|
||||
this@B.h2("no recursion") // keep vigilance
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun test(x : Int, a : Any) : Int {
|
||||
var z = if (x > 3) 3 else x
|
||||
while (z > 0) {
|
||||
if (z > 10) {
|
||||
return test(x - 1, "tail")
|
||||
}
|
||||
test(0, "no tail")
|
||||
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0, "no tail")
|
||||
z = z - 1
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun test(x : Int, a : Any) : Int {
|
||||
if (x == 1) {
|
||||
if (x != 1) {
|
||||
test(0, "no tail")
|
||||
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0, "no tail")
|
||||
return test(0, "tail")
|
||||
} else {
|
||||
return test(x + test(0, "no tail"), "tail")
|
||||
return test(x + <!NON_TAIL_RECURSIVE_CALL!>test<!>(0, "no tail"), "tail")
|
||||
}
|
||||
} else if (x > 0) {
|
||||
return test(x - 1, "tail")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
tailRecursive fun String.repeat(num : Int, acc : StringBuilder = StringBuilder()) : String =
|
||||
if (num == 0) acc.toString()
|
||||
else repeat(num - 1, acc.append(this)!!)
|
||||
else repeat(num - 1, acc.append(this))
|
||||
|
||||
fun box() : String {
|
||||
val s = "a".repeat(10000)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun test() {
|
||||
[tailRecursive] fun g3(counter : Int, x : Any) {
|
||||
if (counter > 0) { g3(counter - 1, "tail") }
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
tailRecursive fun test(counter : Int, a : Any) : Int {
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int, a : Any) : Int<!> {
|
||||
if (counter == 0) return 0
|
||||
|
||||
try {
|
||||
throw Exception()
|
||||
} catch (e : Exception) {
|
||||
return test(counter - 1, "no tail")
|
||||
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1, "no tail")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
tailRecursive fun test(counter : Int, a : Any) : Int {
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int, a : Any) : Int<!> {
|
||||
if (counter == 0) return 0
|
||||
|
||||
try {
|
||||
// do nothing
|
||||
} finally {
|
||||
return test(counter - 1, "no tail")
|
||||
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1, "no tail")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
tailRecursive fun test(counter : Int, a : Any) : Int {
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int, a : Any) : Int<!> {
|
||||
if (counter == 0) return 0
|
||||
|
||||
try {
|
||||
// do nothing
|
||||
} finally {
|
||||
if (counter > 0) {
|
||||
return test(counter - 1, "no tail")
|
||||
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1, "no tail")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
tailRecursive fun test(counter : Int, a : Any) : Int {
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun test(counter : Int, a : Any) : Int<!> {
|
||||
if (counter == 0) return 0
|
||||
|
||||
try {
|
||||
return test(counter - 1, "no tail")
|
||||
return <!TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED!>test<!>(counter - 1, "no tail")
|
||||
} catch (any : Throwable) {
|
||||
return -1
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun test(x : Int, a : Any) : Int =
|
||||
if (x == 1) {
|
||||
test(x - 1, "no tail")
|
||||
1 + test(x - 1, "no tail")
|
||||
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
|
||||
1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
|
||||
} else if (x > 0) {
|
||||
test(x - 1, "tail")
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun test(x : Int, z : Any) : Int {
|
||||
if (x == 10) {
|
||||
return 1 + test(x - 1, "no tail")
|
||||
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
|
||||
}
|
||||
if (x > 0) {
|
||||
return test(x - 1, "tail")
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun test(x : Int, a : Any) : Int {
|
||||
if (x == 0) {
|
||||
return 0
|
||||
} else if (x == 10) {
|
||||
test(0, "no tail")
|
||||
return 1 + test(x - 1, "no tail")
|
||||
<!NON_TAIL_RECURSIVE_CALL!>test<!>(0, "no tail")
|
||||
return 1 + <!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
|
||||
} else {
|
||||
return test(x - 1, "tail")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A {
|
||||
tailRecursive fun f1(c : Int, x : Any) {
|
||||
if (c > 0) {
|
||||
@@ -11,8 +13,8 @@ class A {
|
||||
}
|
||||
}
|
||||
|
||||
tailRecursive fun f3(a : A, x : Any) {
|
||||
a.f3(a, "no tail") // non-tail recursion, could be potentially resolved by condition if (a == this) f3() else a.f3()
|
||||
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun f3(a : A, x : Any)<!> {
|
||||
a.<!NON_TAIL_RECURSIVE_CALL!>f3<!>(a, "no tail") // non-tail recursion, could be potentially resolved by condition if (a == this) f3() else a.f3()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun test(x : Int, e : Any) : Unit {
|
||||
if (x == 1) {
|
||||
test(x - 1, "tail")
|
||||
@@ -5,7 +7,7 @@ tailRecursive fun test(x : Int, e : Any) : Unit {
|
||||
test(x - 1, "tail")
|
||||
return
|
||||
} else if (x == 3) {
|
||||
test(x - 1, "no tail")
|
||||
<!NON_TAIL_RECURSIVE_CALL!>test<!>(x - 1, "no tail")
|
||||
if (x == 3) {
|
||||
test(x - 1, "tail")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun withWhen(counter : Int, x : Any) : Int =
|
||||
when (counter) {
|
||||
0 -> counter
|
||||
50 -> 1 + withWhen(counter - 1, "no tail")
|
||||
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1, "no tail")
|
||||
else -> withWhen(counter - 1, "tail")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun withWhen(counter : Int, d : Any, x : Any) : Int =
|
||||
when (counter) {
|
||||
0 -> counter
|
||||
1, 2 -> withWhen(counter - 1, "1,2", "tail")
|
||||
in 3..49 -> withWhen(counter - 1, "3..49", "tail")
|
||||
50 -> 1 + withWhen(counter - 1, "50", "no tail")
|
||||
50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen<!>(counter - 1, "50", "no tail")
|
||||
!in 0..50 -> withWhen(counter - 1, "!0..50", "tail")
|
||||
else -> withWhen(counter - 1, "else", "tail")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun withWhen(counter : Int, d : Any, x : Any) : Int =
|
||||
if (counter == 0) {
|
||||
0
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
tailRecursive fun withWhen2(counter : Int, x : Any) : Int =
|
||||
when {
|
||||
counter == 0 -> counter
|
||||
counter == 50 -> 1 + withWhen2(counter - 1, "no tail")
|
||||
withWhen2(0, "no tail") == 0 -> withWhen2(counter - 1, "tail")
|
||||
counter == 50 -> 1 + <!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(counter - 1, "no tail")
|
||||
<!NON_TAIL_RECURSIVE_CALL!>withWhen2<!>(0, "no tail") == 0 -> withWhen2(counter - 1, "tail")
|
||||
else -> 1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user