JS: do not create variable for result, if inline call is only return subexpression
This commit is contained in:
@@ -94,6 +94,11 @@ class FunctionInlineMutator private (private val call: JsInvocation, private val
|
||||
}
|
||||
|
||||
private fun processReturns() {
|
||||
if (currentStatement is JsReturn && currentStatement.getExpression() === call) {
|
||||
inliningContext.statementContext.removeMe()
|
||||
return
|
||||
}
|
||||
|
||||
val returnCount = collectInstances(javaClass<JsReturn>(), body).size()
|
||||
if (returnCount == 0) {
|
||||
// TODO return Unit (KT-5647)
|
||||
|
||||
+6
@@ -41,6 +41,12 @@ public class InlineSizeReductionTestGenerated extends AbstractInlineSizeReductio
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("returnInlineCall.kt")
|
||||
public void testReturnInlineCall() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineSizeReduction/cases/returnInlineCall.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleReturnFunction.kt")
|
||||
public void testSimpleReturnFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/inlineSizeReduction/cases/simpleReturnFunction.kt");
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user