Skip to content

Commit

Permalink
KT2482 fix - empty if codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
alextkachman committed Aug 3, 2012
1 parent 40d98dc commit abee22c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ private static boolean isEmptyExpression(JetElement expr) {
@Override
public StackValue visitIfExpression(JetIfExpression expression, StackValue receiver) {
Type asmType = expressionType(expression);
StackValue condition = gen(expression.getCondition());

JetExpression thenExpression = expression.getThen();
JetExpression elseExpression = expression.getElse();
Expand All @@ -261,16 +260,19 @@ public StackValue visitIfExpression(JetIfExpression expression, StackValue recei
StackValue.putTuple0Instance(v);
return StackValue.onStack(asmType);
}
StackValue condition = gen(expression.getCondition());
return generateSingleBranchIf(condition, elseExpression, false);
}
else {
if (isEmptyExpression(elseExpression)) {
StackValue condition = gen(expression.getCondition());
return generateSingleBranchIf(condition, thenExpression, true);
}
}


Label elseLabel = new Label();
StackValue condition = gen(expression.getCondition());
condition.condJump(elseLabel, true, v); // == 0, i.e. false

Label end = new Label();
Expand Down
9 changes: 9 additions & 0 deletions compiler/testData/codegen/regressions/kt2482.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public fun box() : String {
if ( 0 == 0 ) { // Does not crash if either this...
if ( 0 == 0 ) { // ...or this is changed to if ( true )
// Does not crash if the following is uncommented.
//println("foo")
}
}
return "OK"
}
5 changes: 5 additions & 0 deletions compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,9 @@ public void testKt2485() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxMultiFile("regressions/kt2485.kt");
}

public void testKt2482() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxMultiFile("regressions/kt2482.kt");
}
}

0 comments on commit abee22c

Please sign in to comment.