Fix condition generation of empty if
This commit is contained in:
@@ -363,6 +363,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
/* package */ StackValue generateIfExpression(JetIfExpression expression, boolean isStatement) {
|
/* package */ StackValue generateIfExpression(JetIfExpression expression, boolean isStatement) {
|
||||||
Type asmType = expressionType(expression);
|
Type asmType = expressionType(expression);
|
||||||
|
StackValue condition = gen(expression.getCondition());
|
||||||
|
|
||||||
JetExpression thenExpression = expression.getThen();
|
JetExpression thenExpression = expression.getThen();
|
||||||
JetExpression elseExpression = expression.getElse();
|
JetExpression elseExpression = expression.getElse();
|
||||||
@@ -376,22 +377,19 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
if (!asmType.equals(JET_TUPLE0_TYPE)) {
|
if (!asmType.equals(JET_TUPLE0_TYPE)) {
|
||||||
throw new CompilationException("Completely empty 'if' is expected to have Unit type", null, expression);
|
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);
|
return StackValue.onStack(asmType);
|
||||||
}
|
}
|
||||||
StackValue condition = gen(expression.getCondition());
|
|
||||||
return generateSingleBranchIf(condition, expression, elseExpression, false, isStatement);
|
return generateSingleBranchIf(condition, expression, elseExpression, false, isStatement);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (isEmptyExpression(elseExpression)) {
|
if (isEmptyExpression(elseExpression)) {
|
||||||
StackValue condition = gen(expression.getCondition());
|
|
||||||
return generateSingleBranchIf(condition, expression, thenExpression, true, isStatement);
|
return generateSingleBranchIf(condition, expression, thenExpression, true, isStatement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Label elseLabel = new Label();
|
Label elseLabel = new Label();
|
||||||
StackValue condition = gen(expression.getCondition());
|
|
||||||
condition.condJump(elseLabel, true, v); // == 0, i.e. false
|
condition.condJump(elseLabel, true, v); // == 0, i.e. false
|
||||||
|
|
||||||
Label end = new Label();
|
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() {
|
public void testForInSmartCastedToArray() {
|
||||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
blackBoxFile("controlStructures/forInSmartCastedToArray.kt");
|
blackBoxFile("controlStructures/forInSmartCastedToArray.kt");
|
||||||
//System.out.println(generateToText());
|
}
|
||||||
|
|
||||||
|
public void testConditionOfEmptyIf() {
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
|
blackBoxFile("controlStructures/conditionOfEmptyIf.kt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user