Nullability analysis supported for a little more simple cases

This commit is contained in:
Andrey Breslav
2011-06-10 17:21:28 +04:00
parent 41322a8658
commit 9d3abf782c
2 changed files with 82 additions and 4 deletions
@@ -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();
}
+73
View File
@@ -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()
}