JS: do not create variable for result, if inline call is only return subexpression

This commit is contained in:
Alexey Tsvetkov
2015-04-22 16:44:47 +03:00
parent ea41bc4231
commit 6b09b4c2b6
3 changed files with 41 additions and 0 deletions
@@ -0,0 +1,30 @@
package foo
// CHECK_CONTAINS_NO_CALLS: test
// CHECK_VARS_COUNT: function=test count=0
inline fun sign(x: Int): Int {
if (x < 0) return -1
if (x == 0) return 0
return 1
}
fun test(x: Int, y: Int): Int {
if (x != 0) {
return sign(x)
}
return sign(y)
}
fun box(): String {
assertEquals(-1, test(-2, 2))
assertEquals(1, test(2, -2))
assertEquals(-1, test(0, -2))
assertEquals(1, test(0, 2))
assertEquals(0, test(0, 0))
return "OK"
}