Fix condition generation of empty if

This commit is contained in:
Alexander Udalov
2012-11-22 15:37:39 +04:00
parent af601b5a90
commit 8564c20baa
3 changed files with 20 additions and 5 deletions
@@ -363,6 +363,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
/* package */ StackValue generateIfExpression(JetIfExpression expression, boolean isStatement) {
Type asmType = expressionType(expression);
StackValue condition = gen(expression.getCondition());
JetExpression thenExpression = expression.getThen();
JetExpression elseExpression = expression.getElse();
@@ -376,22 +377,19 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (!asmType.equals(JET_TUPLE0_TYPE)) {
throw new CompilationException("Completely empty 'if' is expected to have Unit type", null, expression);
}
StackValue.putTuple0Instance(v);
condition.put(asmType, v);
return StackValue.onStack(asmType);
}
StackValue condition = gen(expression.getCondition());
return generateSingleBranchIf(condition, expression, elseExpression, false, isStatement);
}
else {
if (isEmptyExpression(elseExpression)) {
StackValue condition = gen(expression.getCondition());
return generateSingleBranchIf(condition, expression, thenExpression, true, isStatement);
}
}
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,13 @@
var result = "Fail"
fun setOK(): Boolean {
result = "OK"
return true
}
fun box(): String {
if (setOK()) {
} else {
}
return result
}
@@ -463,6 +463,10 @@ public class ControlStructuresTest extends CodegenTestCase {
public void testForInSmartCastedToArray() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forInSmartCastedToArray.kt");
//System.out.println(generateToText());
}
public void testConditionOfEmptyIf() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/conditionOfEmptyIf.kt");
}
}