From b5712033a88c8852cb84a3333ad06a32f2b9f6a6 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 21 Sep 2015 16:03:30 +0300 Subject: [PATCH] Make DataFlowValue.NULL not static --- .../kotlin/resolve/calls/ArgumentTypeResolver.java | 2 +- .../kotlin/resolve/calls/smartcasts/DataFlowValue.kt | 6 +++++- .../resolve/calls/smartcasts/DataFlowValueFactory.java | 7 +++++-- .../types/expressions/BasicExpressionTypingVisitor.java | 4 ++-- .../types/expressions/PatternMatchingTypingVisitor.java | 3 +-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java index 307256d55f4..5d39c649b6a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java @@ -325,7 +325,7 @@ public class ArgumentTypeResolver { // otherwise not-null will propagate to successive statements // Sample: x?.foo(x.bar()) // Inside foo call, x is not-nullable if (CallUtilPackage.isSafeCall(call)) { - initialDataFlowInfo = initialDataFlowInfo.disequate(receiverDataFlowValue, DataFlowValue.NULL); + initialDataFlowInfo = initialDataFlowInfo.disequate(receiverDataFlowValue, DataFlowValue.nullValue(builtIns)); } } infoForArguments.setInitialDataFlowInfo(initialDataFlowInfo); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt index 92f0e5e8051..12dac732e39 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt @@ -72,7 +72,11 @@ class DataFlowValue(val id: Any?, val type: JetType, val kind: DataFlowValue.Kin 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) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java index 01d6d1ec451..0a9f8b72ec6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage; import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext; 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.types.JetType; import org.jetbrains.kotlin.types.TypeUtils; @@ -66,11 +67,13 @@ public class DataFlowValueFactory { ) { if (expression instanceof JetConstantExpression) { 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 (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))) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index d6e3f77793c..12d6a0aa83f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -843,7 +843,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { } else { 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); 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 if ((rightType != null && KotlinBuiltIns.isNothingOrNullableNothing(rightType) && !rightType.isMarkedNullable()) || !rightDataFlowInfo.getNullability(leftValue).canBeNull()) { - dataFlowInfo = dataFlowInfo.disequate(leftValue, DataFlowValue.NULL); + dataFlowInfo = dataFlowInfo.disequate(leftValue, DataFlowValue.nullValue(components.builtIns)); } } JetType type = resolvedCall.getResultingDescriptor().getReturnType(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java index 26ccd9bc575..9f25717840f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java @@ -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.util.CallMaker; 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.checker.JetTypeChecker; import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage; @@ -100,7 +99,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { } DataFlowValue subjectDataFlowValue = subjectExpression != null ? DataFlowValueFactory.createDataFlowValue(subjectExpression, subjectType, context) - : DataFlowValue.NULL; + : DataFlowValue.nullValue(components.builtIns); // TODO : exhaustive patterns