Nullability analysis supported for a little more simple cases
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user