KT-2164 !! does not propagate nullability information

This commit is contained in:
Alexander Udalov
2012-06-15 22:03:00 +04:00
parent d777313132
commit 845c3198bd
2 changed files with 43 additions and 0 deletions
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.resolve.calls.CallMaker;
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResultsUtil;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
import org.jetbrains.jet.lang.resolve.constants.*;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
@@ -784,6 +785,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (isKnownToBeNotNull(baseExpression, context)) {
context.trace.report(UNNECESSARY_NOT_NULL_ASSERTION.on(operationSign, type));
}
else {
DataFlowValue value = DataFlowValueFactory.INSTANCE.createDataFlowValue(baseExpression, type, context.trace.getBindingContext());
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
}
return DataFlowUtils.checkType(TypeUtils.makeNotNullable(type), expression, context, dataFlowInfo);
}
@@ -0,0 +1,38 @@
//KT-2164 !! does not propagate nullability information
package kt2164
fun foo(x: Int): Int = x + 1
fun main(args : Array<String>) {
val x: Int? = null
foo(<!TYPE_MISMATCH!>x<!>)
if (x != null) {
foo(x)
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
foo(x)
}
foo(<!TYPE_MISMATCH!>x<!>)
if (x != null) {
foo(x)
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
foo(x)
} else {
foo(<!TYPE_MISMATCH!>x<!>)
foo(x!!)
foo(x)
}
foo(x)
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
foo(x)
val y: Int? = null
y!!
y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
foo(y)
foo(y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
}