JS: do not extract expressions, when inline call can be expression

This commit is contained in:
Alexey Tsvetkov
2015-04-14 18:12:25 +03:00
parent bf5300a849
commit ff5090136c
4 changed files with 74 additions and 16 deletions
@@ -0,0 +1,21 @@
package foo
// CHECK_CONTAINS_NO_CALLS: test
// COUNT_VARS: function=test count=0
// 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(x: Int): Int =
evaluate {
evaluate { 2 } * evaluate { x }
}
fun box(): String {
assertEquals(6, test(3))
assertEquals(8, test(4))
return "OK"
}