diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index fb22940f987..086a21148e6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -1064,6 +1064,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { JetType rightType = rightTypeInfo.getType(); DataFlowInfo dataFlowInfo = resolvedCall.getDataFlowInfoForArguments().getResultInfo(); + if (leftType != null && rightType != null && KotlinBuiltIns.getInstance().isNothingOrNullableNothing(rightType) && !rightType.isNullable()) { + DataFlowValue value = DataFlowValueFactory.createDataFlowValue(left, leftType, context.trace.getBindingContext()); + dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL); + } JetType type = resolvedCall.getResultingDescriptor().getReturnType(); if (type == null || rightType == null) return JetTypeInfo.create(null, dataFlowInfo); diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvis.kt b/compiler/testData/diagnostics/tests/smartCasts/elvis.kt new file mode 100644 index 00000000000..f7300ef3527 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvis.kt @@ -0,0 +1,11 @@ +class C { + fun foo() {} +} + +fun test(a: C?, nn: () -> Nothing?) { + a ?: nn() + a.foo() + + a ?: return + a.foo() +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 3b9e1d4c358..0027562f4ee 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -9014,6 +9014,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("elvis.kt") + public void testElvis() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/elvis.kt"); + doTest(fileName); + } + @TestMetadata("kt1461.kt") public void testKt1461() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt1461.kt");