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
@@ -48,7 +48,9 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
@@ -108,7 +110,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
return getTypeInfoWhenOnlyOneBranchIsPresent(
thenBranch, thenScope, thenInfo, elseInfo, contextWithExpectedType, ifExpression, isStatement);
}
return JetTypeInfo.create(null, context.dataFlowInfo);
return DataFlowUtils.checkImplicitCast(KotlinBuiltIns.getInstance().getUnitType(), ifExpression, contextWithExpectedType,
isStatement, thenInfo.or(elseInfo));
}
if (thenBranch == null) {
return getTypeInfoWhenOnlyOneBranchIsPresent(