Pass DataFlowInfo through when-conditions

This commit is contained in:
Alexander Udalov
2012-06-21 21:17:13 +04:00
parent 1ae1f13821
commit 38fc57ae42
4 changed files with 11 additions and 7 deletions
@@ -116,9 +116,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
if (newDataFlowInfo == null) {
newDataFlowInfo = context.dataFlowInfo;
}
else {
newDataFlowInfo = newDataFlowInfo.and(context.dataFlowInfo);
}
}
JetExpression bodyExpression = whenEntry.getExpression();
if (bodyExpression != null) {
@@ -259,14 +256,21 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
JetExpression expression = pattern.getExpression();
if (expression == null) return;
JetType type = facade.getTypeInfo(expression, context.replaceScope(scopeToExtend)).getType();
if (type == null) return;
if (conditionExpected) {
JetType booleanType = JetStandardLibrary.getInstance().getBooleanType();
if (type != null && !JetTypeChecker.INSTANCE.equalTypes(booleanType, type)) {
if (!JetTypeChecker.INSTANCE.equalTypes(booleanType, type)) {
context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(pattern, type));
}
return;
}
checkTypeCompatibility(type, subjectType, pattern);
DataFlowInfo dataFlowInfo = context.dataFlowInfo;
DataFlowValue expressionDataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, type, context.trace.getBindingContext());
for (DataFlowValue subjectVariable : subjectVariables) {
dataFlowInfo = dataFlowInfo.equate(subjectVariable, expressionDataFlowValue);
}
result.set(dataFlowInfo);
}
@Override