KT2482 fix - empty if codegen
This commit is contained in:
@@ -244,7 +244,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
@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();
|
||||
@@ -261,16 +260,19 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
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();
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -486,4 +486,9 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
blackBoxMultiFile("regressions/kt2485.kt");
|
||||
}
|
||||
|
||||
public void testKt2482() {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
blackBoxMultiFile("regressions/kt2482.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user