JS: inline all calls in a statement in one pass

This commit is contained in:
Alexey Tsvetkov
2015-03-27 21:10:52 +03:00
parent c8453ec0d9
commit 05c44db80f
6 changed files with 101 additions and 89 deletions
@@ -0,0 +1,30 @@
package foo
// CHECK_CONTAINS_NO_CALLS: test
// A copy of stdlib run function.
// Copied to not to depend on run implementation.
// It's important, that the body is just `return fn()`.
inline fun evaluate<T>(fn: ()->T): T = fn()
fun test(n: Int): Int {
return evaluate {
var i = n
var sum = 0
while (i > 0) {
sum += i
i--
}
sum
}
}
fun box(): String {
assertEquals(6, test(3))
assertEquals(0, test(0))
assertEquals(0, test(-1))
return "OK"
}