diff --git a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java index f1ce555fc02..c5562352975 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java @@ -1291,7 +1291,6 @@ public class JetTypeInferrer { JetExpression condition = expression.getCondition(); checkCondition(scope, condition); - // TODO : change types according to is and null checks JetExpression elseBranch = expression.getElse(); JetExpression thenBranch = expression.getThen(); @@ -1300,7 +1299,10 @@ public class JetTypeInferrer { if (elseBranch == null) { if (thenBranch != null) { - getType(scope, thenBranch, true, thenInfo); + JetType type = getType(scope, thenBranch, true, thenInfo); + if (type != null && JetStandardClasses.isNothing(type)) { + resultDataFlowInfo = elseInfo; + } result = JetStandardClasses.getUnitType(); } } @@ -1401,11 +1403,14 @@ public class JetTypeInferrer { @Override public void visitWhileExpression(JetWhileExpression expression) { - checkCondition(scope, expression.getCondition()); + JetExpression condition = expression.getCondition(); + checkCondition(scope, condition); JetExpression body = expression.getBody(); if (body != null) { - getType(scope, body, true); + DataFlowInfo conditionInfo = condition == null ? dataFlowInfo : extractDataFlowInfoFromCondition(condition, true); + getType(scope, body, true, conditionInfo); } + resultDataFlowInfo = condition == null ? null : extractDataFlowInfoFromCondition(condition, false); result = JetStandardClasses.getUnitType(); } diff --git a/idea/testData/checker/Nullability.jet b/idea/testData/checker/Nullability.jet index 2d4603c14e0..d13f733ce93 100644 --- a/idea/testData/checker/Nullability.jet +++ b/idea/testData/checker/Nullability.jet @@ -65,4 +65,77 @@ fun test() { else { out?.println(3) } + + out?.println() + ins?.read() + + if (ins != null) { + ins.read() + out?.println() + if (out != null) { + ins.read(); + out.println(); + } + } + + if (out != null && ins != null) { + ins.read(); + out.println(); + } + + if (out == null) { + out?.println() + } else { + out.println() + } + + if (out != null && ins != null || out != null) { + ins?.read(); + out.println(); + } + + if (out == null || out.println(0) == ()) { + out?.println(1) + } + else { + out.println(2) + } + + if (out != null && out.println() == ()) { + out.println(); + } + else { + out?.println(); + } + + if (out == null || out != null && out.println() == ()) { + out?.println(); + } + else { + out.println(); + } + + if (1 == 2 || out != null && out.println(1) == ()) { + out?.println(2); + } + else { + out?.println(3) + } + + if (1 > 2) { + if (out == null) return; + out.println(); + } + out?.println(); + + while (out != null) { + out.println(); + } + out?.println(); + + while (out == null) { + out?.println(); + } + out.println() + }