diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java
index f43a469a2f5..5d384c0623c 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java
@@ -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
diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.jet b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.jet
index 5582e7b2346..06b49dbf4d5 100644
--- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.jet
+++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/When.jet
@@ -11,7 +11,7 @@ fun foo() {
}
when (x) {
- 0 -> { if (x == null) return }
+ 0 -> { if (x == null) return }
else -> { if (x == null) return }
}
bar(x)
diff --git a/compiler/testData/diagnostics/tests/regressions/Jet169.jet b/compiler/testData/diagnostics/tests/regressions/Jet169.jet
index 9b806fd22c1..9761d8ec20f 100644
--- a/compiler/testData/diagnostics/tests/regressions/Jet169.jet
+++ b/compiler/testData/diagnostics/tests/regressions/Jet169.jet
@@ -1,7 +1,7 @@
fun set(key : String, value : String) {
val a : String? = ""
when (a) {
- "" -> a.get(0)
+ "" -> a.get(0)
is String, is Any -> a.compareTo("")
else -> a.toString()
}
diff --git a/idea/testData/checker/regression/Jet169.jet b/idea/testData/checker/regression/Jet169.jet
index 35ace683078..e38e1eb9a05 100644
--- a/idea/testData/checker/regression/Jet169.jet
+++ b/idea/testData/checker/regression/Jet169.jet
@@ -1,7 +1,7 @@
fun set(key : String, value : String) {
val a : String? = ""
when (a) {
- "" -> a.get(0)
+ "" -> a.get(0)
is String, is Any -> a.compareTo("")
else -> a.toString()
}