All tests for TCO moved to box (with diagnostics marked up)

This commit is contained in:
Andrey Breslav
2013-12-06 11:08:29 +04:00
parent 1849643e52
commit 71be3bcec5
19 changed files with 205 additions and 97 deletions
@@ -0,0 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive 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,8 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun noTails()<!> {
// nothing here
}
fun box(): String {
noTails()
return "OK"
}
@@ -0,0 +1,17 @@
tailRecursive 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,12 @@
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,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
tailRecursive 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,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun foo()<!> {
run {
<!NON_TAIL_RECURSIVE_CALL!>foo<!>()
}
}
fun run(a: Any) {}
fun box(): String {
foo()
return "OK"
}
@@ -0,0 +1,10 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive fun foo()<!> {
fun bar() {
<!NON_TAIL_RECURSIVE_CALL!>foo<!>()
}
}
fun box(): String {
foo()
return "OK"
}
@@ -0,0 +1,9 @@
tailRecursive fun foo(x: Int) {
if (x == 0) return
(return foo(x - 1))
}
fun box(): String {
foo(1000000)
return "OK"
}
@@ -0,0 +1,11 @@
tailRecursive fun foo(x: Int) {
return if (x > 0) {
(foo(x - 1))
}
else Unit.VALUE
}
fun box(): String {
foo(1000000)
return "OK"
}
@@ -0,0 +1,9 @@
tailRecursive fun foo(x: Int) {
if (x == 0) return
return (foo(x - 1))
}
fun box(): String {
foo(1000000)
return "OK"
}
@@ -0,0 +1,15 @@
<!NO_TAIL_CALLS_FOUND!>tailRecursive 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"
}