extract DataFlowInfo from when-condition + more tests for kt2146

This commit is contained in:
Alexander Udalov
2012-06-22 13:18:45 +04:00
parent b5ba7123d5
commit 3f4e2514ea
2 changed files with 40 additions and 3 deletions
@@ -263,13 +263,19 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
public void visitExpressionPattern(JetExpressionPattern pattern) {
JetExpression expression = pattern.getExpression();
if (expression == null) return;
JetType type = facade.getTypeInfo(expression, context.replaceScope(scopeToExtend)).getType();
JetTypeInfo typeInfo = facade.getTypeInfo(expression, context.replaceScope(scopeToExtend));
JetType type = typeInfo.getType();
if (type == null) return;
if (conditionExpected) {
JetType booleanType = JetStandardLibrary.getInstance().getBooleanType();
if (!JetTypeChecker.INSTANCE.equalTypes(booleanType, type)) {
context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(pattern, type));
}
else {
DataFlowInfo ifInfo = DataFlowUtils.extractDataFlowInfoFromCondition(expression, true, scopeToExtend, context);
DataFlowInfo elseInfo = DataFlowUtils.extractDataFlowInfoFromCondition(expression, false, null, context);
result.set(Pair.create(ifInfo, elseInfo));
}
return;
}
checkTypeCompatibility(type, subjectType, pattern);