KT-5773 Smart cast doesn't work with Nothing on the rhs of "?:"

#KT-5773 FIxed
This commit is contained in:
Andrey Breslav
2014-09-15 18:24:13 +04:00
parent 3a806713fd
commit f1cf446e10
3 changed files with 21 additions and 0 deletions
@@ -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);
@@ -0,0 +1,11 @@
class C {
fun foo() {}
}
fun test(a: C?, nn: () -> Nothing?) {
a ?: nn()
a<!UNSAFE_CALL!>.<!>foo()
a ?: return
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
}
@@ -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");