Make DataFlowValue.NULL not static
This commit is contained in:
@@ -325,7 +325,7 @@ public class ArgumentTypeResolver {
|
|||||||
// otherwise not-null will propagate to successive statements
|
// otherwise not-null will propagate to successive statements
|
||||||
// Sample: x?.foo(x.bar()) // Inside foo call, x is not-nullable
|
// Sample: x?.foo(x.bar()) // Inside foo call, x is not-nullable
|
||||||
if (CallUtilPackage.isSafeCall(call)) {
|
if (CallUtilPackage.isSafeCall(call)) {
|
||||||
initialDataFlowInfo = initialDataFlowInfo.disequate(receiverDataFlowValue, DataFlowValue.NULL);
|
initialDataFlowInfo = initialDataFlowInfo.disequate(receiverDataFlowValue, DataFlowValue.nullValue(builtIns));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
infoForArguments.setInitialDataFlowInfo(initialDataFlowInfo);
|
infoForArguments.setInitialDataFlowInfo(initialDataFlowInfo);
|
||||||
|
|||||||
+5
-1
@@ -72,7 +72,11 @@ class DataFlowValue(val id: Any?, val type: JetType, val kind: DataFlowValue.Kin
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
val NULL = DataFlowValue(Object(), KotlinBuiltIns.getInstance().nullableNothingType, Kind.OTHER, Nullability.NULL)
|
@JvmStatic
|
||||||
|
fun nullValue(builtIns: KotlinBuiltIns) = DataFlowValue(
|
||||||
|
Object(), builtIns.nullableNothingType, Kind.OTHER, Nullability.NULL
|
||||||
|
)
|
||||||
|
|
||||||
val ERROR = DataFlowValue(Object(), ErrorUtils.createErrorType("Error type for data flow"), Kind.OTHER, Nullability.IMPOSSIBLE)
|
val ERROR = DataFlowValue(Object(), ErrorUtils.createErrorType("Error type for data flow"), Kind.OTHER, Nullability.IMPOSSIBLE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
|||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
|
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.*;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.*;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
import org.jetbrains.kotlin.types.JetType;
|
||||||
import org.jetbrains.kotlin.types.TypeUtils;
|
import org.jetbrains.kotlin.types.TypeUtils;
|
||||||
@@ -66,11 +67,13 @@ public class DataFlowValueFactory {
|
|||||||
) {
|
) {
|
||||||
if (expression instanceof JetConstantExpression) {
|
if (expression instanceof JetConstantExpression) {
|
||||||
JetConstantExpression constantExpression = (JetConstantExpression) expression;
|
JetConstantExpression constantExpression = (JetConstantExpression) expression;
|
||||||
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
|
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) {
|
||||||
|
return DataFlowValue.nullValue(DescriptorUtilsKt.getBuiltIns(containingDeclarationOrModule));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (type.isError()) return DataFlowValue.ERROR;
|
if (type.isError()) return DataFlowValue.ERROR;
|
||||||
if (isNullableNothing(type)) {
|
if (isNullableNothing(type)) {
|
||||||
return DataFlowValue.NULL; // 'null' is the only inhabitant of 'Nothing?'
|
return DataFlowValue.nullValue(DescriptorUtilsKt.getBuiltIns(containingDeclarationOrModule)); // 'null' is the only inhabitant of 'Nothing?'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ExpressionTypingUtils.isExclExclExpression(JetPsiUtil.deparenthesize(expression))) {
|
if (ExpressionTypingUtils.isExclExclExpression(JetPsiUtil.deparenthesize(expression))) {
|
||||||
|
|||||||
+2
-2
@@ -843,7 +843,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataFlowValue value = createDataFlowValue(baseExpression, baseType, context);
|
DataFlowValue value = createDataFlowValue(baseExpression, baseType, context);
|
||||||
baseTypeInfo = baseTypeInfo.replaceDataFlowInfo(dataFlowInfo.disequate(value, DataFlowValue.NULL));
|
baseTypeInfo = baseTypeInfo.replaceDataFlowInfo(dataFlowInfo.disequate(value, DataFlowValue.nullValue(components.builtIns)));
|
||||||
}
|
}
|
||||||
JetType resultingType = TypeUtils.makeNotNullable(baseType);
|
JetType resultingType = TypeUtils.makeNotNullable(baseType);
|
||||||
if (context.contextDependency == DEPENDENT) {
|
if (context.contextDependency == DEPENDENT) {
|
||||||
@@ -1186,7 +1186,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
// left argument is considered not-null if it's not-null also in right part or if we have jump in right part
|
// left argument is considered not-null if it's not-null also in right part or if we have jump in right part
|
||||||
if ((rightType != null && KotlinBuiltIns.isNothingOrNullableNothing(rightType) && !rightType.isMarkedNullable())
|
if ((rightType != null && KotlinBuiltIns.isNothingOrNullableNothing(rightType) && !rightType.isMarkedNullable())
|
||||||
|| !rightDataFlowInfo.getNullability(leftValue).canBeNull()) {
|
|| !rightDataFlowInfo.getNullability(leftValue).canBeNull()) {
|
||||||
dataFlowInfo = dataFlowInfo.disequate(leftValue, DataFlowValue.NULL);
|
dataFlowInfo = dataFlowInfo.disequate(leftValue, DataFlowValue.nullValue(components.builtIns));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JetType type = resolvedCall.getResultingDescriptor().getReturnType();
|
JetType type = resolvedCall.getResultingDescriptor().getReturnType();
|
||||||
|
|||||||
+1
-2
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue;
|
|||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory;
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory;
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
|
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
|
|
||||||
import org.jetbrains.kotlin.types.*;
|
import org.jetbrains.kotlin.types.*;
|
||||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage;
|
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage;
|
||||||
@@ -100,7 +99,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
DataFlowValue subjectDataFlowValue = subjectExpression != null
|
DataFlowValue subjectDataFlowValue = subjectExpression != null
|
||||||
? DataFlowValueFactory.createDataFlowValue(subjectExpression, subjectType, context)
|
? DataFlowValueFactory.createDataFlowValue(subjectExpression, subjectType, context)
|
||||||
: DataFlowValue.NULL;
|
: DataFlowValue.nullValue(components.builtIns);
|
||||||
|
|
||||||
// TODO : exhaustive patterns
|
// TODO : exhaustive patterns
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user