Support empty if-statements

Type-check "if (...) ;" to Unit, report "implicit cast to Unit", propagate data
flow info out of its condition

 #KT-2478 Fixed
This commit is contained in:
Alexander Udalov
2013-12-02 20:30:55 +04:00
parent f045a06dee
commit 4cd4026174
7 changed files with 72 additions and 8 deletions
@@ -357,7 +357,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return genQualified(receiver, expression.getBaseExpression());
}
private static boolean isEmptyExpression(JetElement expr) {
private static boolean isEmptyExpression(@Nullable JetElement expr) {
if (expr == null) {
return true;
}
@@ -383,10 +383,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
JetExpression thenExpression = expression.getThen();
JetExpression elseExpression = expression.getElse();
if (thenExpression == null && elseExpression == null) {
throw new CompilationException("Both brunches of if/else are null", null, expression);
}
if (isEmptyExpression(thenExpression)) {
if (isEmptyExpression(elseExpression)) {
condition.put(asmType, v);