Support codegen of empty for-loop

#KT-3009 Fixed
 EA-35742 fixed
This commit is contained in:
Alexander Udalov
2013-12-02 20:53:50 +04:00
parent 61ff9eb45b
commit 4aa6a42483
3 changed files with 24 additions and 1 deletions
@@ -652,7 +652,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
protected abstract void increment(@NotNull Label loopExit);
public void body() {
gen(forExpression.getBody(), Type.VOID_TYPE);
JetExpression body = forExpression.getBody();
if (body != null) {
gen(body, Type.VOID_TYPE);
}
}
private void scheduleLeaveVariable(Runnable runnable) {
@@ -0,0 +1,15 @@
var index = 0
val iterator = object : Iterator<Int> {
override fun hasNext() = index < 5
override fun next() = index++
}
fun box(): String {
for (x in 1..5);
for (x in iterator);
if (index != 5) return "Fail: $index"
return "OK"
}
@@ -1432,6 +1432,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/controlStructures/emptyDoWhile.kt");
}
@TestMetadata("emptyFor.kt")
public void testEmptyFor() throws Exception {
doTest("compiler/testData/codegen/box/controlStructures/emptyFor.kt");
}
@TestMetadata("emptyIf.kt")
public void testEmptyIf() throws Exception {
doTest("compiler/testData/codegen/box/controlStructures/emptyIf.kt");