Generate substatements as statements too

Preventing pushing on stack redundant Unit instances

 #KT-5667 fixed
This commit is contained in:
Denis Zharkov
2014-09-19 16:04:11 +04:00
committed by Alexander Udalov
parent 081d2cf95c
commit 4ed744428b
3 changed files with 43 additions and 1 deletions
@@ -261,7 +261,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
public void gen(JetElement expr, Type type) {
StackValue value = gen(expr);
StackValue value = Type.VOID_TYPE.equals(type) ? genStatement(expr) : gen(expr);
value.put(type, v);
}
@@ -0,0 +1,36 @@
fun foo() {
val array = intArray(1,2,3)
var count = 0
for (element in array) if (element > 0) count++
while (count > 0) if (count > 0) count++
if (count == 1)
if (count != 1)
count++
else
print("1")
else
print("2")
when (count) {
1 -> if (count == 1) count++ else print("123")
else -> if (count == 1) count++ else print("123")
}
for (element in array)
when (element) {
1 -> if (count == 1) count++ else print("123")
else -> if (count == 1) count++ else print("123")
}
while (count > 0)
when (count) {
1 -> if (count == 1) count++ else print("123")
else -> if (count == 1) count++ else print("123")
}
}
// 0 valueOf
// 0 GETSTATIC
@@ -341,6 +341,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
doTest(fileName);
}
@TestMetadata("statementsComposition.kt")
public void testStatementsComposition() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/statements/statementsComposition.kt");
doTest(fileName);
}
@TestMetadata("tryCatchFinally.kt")
public void testTryCatchFinally() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/statements/tryCatchFinally.kt");