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 f637d1ddd55..f595a08fdc5 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 @@ -177,7 +177,13 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { context.trace.report(EXPECTED_CONDITION.on(condition)); } if (pattern != null) { - newDataFlowInfo.set(checkPatternType(pattern, subjectType, subjectExpression == null, scopeToExtend, context, subjectVariables)); + Pair result = checkPatternType(pattern, subjectType, subjectExpression == null, scopeToExtend, context, subjectVariables); + if (condition.isNegated()) { + newDataFlowInfo.set(Pair.create(result.second, result.first)); + } + else { + newDataFlowInfo.set(result); + } } } diff --git a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt2146.jet b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt2146.jet index 579f1095ba5..acf19b90e48 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt2146.jet +++ b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt2146.jet @@ -10,8 +10,7 @@ fun f1(s: Int?): Int { fun f2(s: Int?): Int { return when (s) { - is 4 -> s - is null -> s + !is Int -> s else -> s } } @@ -38,3 +37,17 @@ fun f5(s: Int?): Int { else -> 0 } } + +fun f6(s: Int?): Int { + return when { + s is Int -> s + else -> s + } +} + +fun f7(s: Int?): Int { + return when { + s !is Int -> s + else -> s + } +}