Renamed JetType.isNullable() to isMarkedNullable()

This commit is contained in:
Valentin Kipyatkov
2014-12-03 21:36:10 +03:00
parent c76e69af62
commit b8d1f115bf
53 changed files with 91 additions and 96 deletions
@@ -74,7 +74,7 @@ public fun or(predicates: Collection<TypePredicate>): TypePredicate? =
fun JetType.getSubtypesPredicate(): TypePredicate {
return when {
KotlinBuiltIns.isAnyOrNullableAny(this) && isNullable() -> AllTypes
KotlinBuiltIns.isAnyOrNullableAny(this) && isMarkedNullable() -> AllTypes
TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, this) -> AllSubtypes(this)
else -> SingleType(this)
}
@@ -52,7 +52,7 @@ public class CompileTimeConstantUtils {
JetType parameterType = parameterDescriptor.getType();
JetTypeReference typeReference = parameter.getTypeReference();
if (typeReference != null) {
if (parameterType.isNullable()) {
if (parameterType.isMarkedNullable()) {
trace.report(NULLABLE_TYPE_OF_ANNOTATION_MEMBER.on(typeReference));
}
else if (!isAcceptableTypeForAnnotationParameter(parameterType)) {
@@ -82,7 +82,7 @@ public class CompileTimeConstantUtils {
List<TypeProjection> arguments = parameterType.getArguments();
if (arguments.size() == 1) {
JetType arrayType = arguments.get(0).getType();
if (arrayType.isNullable()) {
if (arrayType.isMarkedNullable()) {
return false;
}
ClassDescriptor arrayTypeDescriptor = TypeUtils.getClassDescriptor(arrayType);
@@ -84,7 +84,7 @@ public class PossiblyBareType {
public boolean isNullable() {
if (isBare()) return isBareTypeNullable();
return getActualType().isNullable();
return getActualType().isMarkedNullable();
}
public PossiblyBareType makeNullable() {
@@ -67,7 +67,7 @@ public class CallResolverUtil {
List<TypeProjection> newArguments = Lists.newArrayList();
newArguments.addAll(arguments.subList(0, arguments.size() - 1));
newArguments.add(new TypeProjectionImpl(Variance.INVARIANT, DONT_CARE));
return new JetTypeImpl(type.getAnnotations(), type.getConstructor(), type.isNullable(), newArguments, type.getMemberScope());
return new JetTypeImpl(type.getAnnotations(), type.getConstructor(), type.isMarkedNullable(), newArguments, type.getMemberScope());
}
private static boolean hasReturnTypeDependentOnUninferredParams(
@@ -115,7 +115,7 @@ public class CallResolverUtil {
fakeTypeArguments.add(new TypeProjectionImpl(typeProjection.getProjectionKind(), DONT_CARE));
}
return new JetTypeImpl(
receiverType.getAnnotations(), receiverType.getConstructor(), receiverType.isNullable(),
receiverType.getAnnotations(), receiverType.getConstructor(), receiverType.isMarkedNullable(),
fakeTypeArguments, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true));
}
@@ -596,7 +596,7 @@ public class CandidateResolver {
JetType receiverArgumentType = receiverArgument.getType();
BindingContext bindingContext = trace.getBindingContext();
if (!safeAccess && !receiverParameter.getType().isNullable() && receiverArgumentType.isNullable()) {
if (!safeAccess && !receiverParameter.getType().isMarkedNullable() && receiverArgumentType.isMarkedNullable()) {
if (!SmartCastUtils.canBeSmartCast(receiverParameter, receiverArgument, bindingContext, context.dataFlowInfo)) {
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
return UNSAFE_CALL_ERROR;
@@ -222,7 +222,7 @@ public class InlineCallResolverExtension implements CallResolverExtension {
JetType type = descriptor.getReturnType();
return type != null &&
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) &&
!type.isNullable() &&
!type.isMarkedNullable() &&
!InlineUtil.hasNoinlineAnnotation(descriptor);
}
@@ -28,7 +28,6 @@ import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.TypesPackage;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
@@ -62,7 +61,7 @@ public class DataFlowValueFactory {
if (receiverValue instanceof TransientReceiver || receiverValue instanceof ScriptReceiver) {
// SCRIPT: smartcasts data flow
JetType type = receiverValue.getType();
boolean nullable = type.isNullable() || TypeUtils.hasNullableSuperType(type);
boolean nullable = type.isMarkedNullable() || TypeUtils.hasNullableSuperType(type);
return new DataFlowValue(receiverValue, type, nullable, Nullability.NOT_NULL);
}
else if (receiverValue instanceof ClassReceiver || receiverValue instanceof ExtensionReceiver) {
@@ -110,7 +110,7 @@ import static org.jetbrains.jet.lang.resolve.calls.smartcasts.Nullability.NOT_NU
Set<JetType> enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1);
JetType originalType = key.getType();
if (originalType.isNullable()) {
if (originalType.isMarkedNullable()) {
enrichedTypes.add(TypeUtils.makeNotNullable(originalType));
}
for (JetType type : types) {
@@ -152,7 +152,7 @@ import static org.jetbrains.jet.lang.resolve.calls.smartcasts.Nullability.NOT_NU
if (value.getType().equals(type)) return this;
if (getPossibleTypes(value).contains(type)) return this;
ImmutableMap<DataFlowValue, Nullability> newNullabilityInfo =
type.isNullable() ? EMPTY_NULLABILITY_INFO : ImmutableMap.of(value, NOT_NULL);
type.isMarkedNullable() ? EMPTY_NULLABILITY_INFO : ImmutableMap.of(value, NOT_NULL);
SetMultimap<DataFlowValue, JetType> newTypeInfo = ImmutableSetMultimap.of(value, type);
return new DelegatingDataFlowInfo(this, newNullabilityInfo, newTypeInfo);
}
@@ -190,7 +190,7 @@ public class SmartCastUtils {
@NotNull BindingContext bindingContext,
@NotNull DataFlowInfo dataFlowInfo
) {
if (!receiver.getType().isNullable()) return true;
if (!receiver.getType().isMarkedNullable()) return true;
List<JetType> smartCastVariants = getSmartCastVariants(receiver, bindingContext, dataFlowInfo);
for (JetType smartCastVariant : smartCastVariants) {
@@ -152,7 +152,7 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
JetType type = parameter.getReturnType();
if (type != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)) {
if (!InlineUtil.hasNoinlineAnnotation(parameter)) {
if (type.isNullable()) {
if (type.isMarkedNullable()) {
if (trace != null) {
trace.report(Errors.NULLABLE_INLINE_PARAMETER.on(expression, expression, functionDescriptor));
}
@@ -112,7 +112,7 @@ public class CastDiagnosticsUtil {
*/
public static boolean isCastErased(@NotNull JetType supertype, @NotNull JetType subtype, @NotNull JetTypeChecker typeChecker) {
// cast between T and T? is always OK
if (supertype.isNullable() || subtype.isNullable()) {
if (supertype.isMarkedNullable() || subtype.isMarkedNullable()) {
return isCastErased(TypeUtils.makeNotNullable(supertype), TypeUtils.makeNotNullable(subtype), typeChecker);
}
@@ -154,7 +154,7 @@ public class CastDiagnosticsUtil {
* result = List<*>, some arguments were not inferred, replaced with '*'
*/
public static TypeReconstructionResult findStaticallyKnownSubtype(@NotNull JetType supertype, @NotNull TypeConstructor subtypeConstructor) {
assert !supertype.isNullable() : "This method only makes sense for non-nullable types";
assert !supertype.isMarkedNullable() : "This method only makes sense for non-nullable types";
// Assume we are casting an expression of type Collection<Foo> to List<Bar>
// First, let's make List<T>, where T is a type variable
@@ -75,7 +75,7 @@ public class TypeUnifier {
}
// Foo? ~ X? => Foo ~ X
if (known.isNullable() && withVariables.isNullable()) {
if (known.isMarkedNullable() && withVariables.isMarkedNullable()) {
doUnify(
new TypeProjectionImpl(knownProjectionKind, TypeUtils.makeNotNullable(known)),
new TypeProjectionImpl(withVariablesProjectionKind, TypeUtils.makeNotNullable(withVariables)),
@@ -93,7 +93,7 @@ public class TypeUnifier {
}
// Foo ~ X? => fail
if (!known.isNullable() && withVariables.isNullable()) {
if (!known.isMarkedNullable() && withVariables.isMarkedNullable()) {
result.fail();
return;
}
@@ -106,7 +106,7 @@ public class TypeUnifier {
}
// Foo? ~ Foo || in Foo ~ Foo || Foo ~ Bar
boolean structuralMismatch = known.isNullable() != withVariables.isNullable()
boolean structuralMismatch = known.isMarkedNullable() != withVariables.isMarkedNullable()
|| knownProjectionKind != withVariablesProjectionKind
|| !known.getConstructor().equals(withVariables.getConstructor());
if (structuralMismatch) {
@@ -1079,7 +1079,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetType rightType = rightTypeInfo.getType();
DataFlowInfo dataFlowInfo = resolvedCall.getDataFlowInfoForArguments().getResultInfo();
if (leftType != null && rightType != null && KotlinBuiltIns.isNothingOrNullableNothing(rightType) && !rightType.isNullable()) {
if (leftType != null && rightType != null && KotlinBuiltIns.isNothingOrNullableNothing(rightType) && !rightType.isMarkedNullable()) {
DataFlowValue value = createDataFlowValue(left, leftType, context.trace.getBindingContext());
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
}
@@ -289,7 +289,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
context.trace.report(DYNAMIC_NOT_ALLOWED.on(typeReferenceAfterIs));
}
if (!subjectType.isNullable() && targetType.isNullable()) {
if (!subjectType.isMarkedNullable() && targetType.isMarkedNullable()) {
JetTypeElement element = typeReferenceAfterIs.getTypeElement();
assert element instanceof JetNullableType : "element must be instance of " + JetNullableType.class.getName();
JetNullableType nullableType = (JetNullableType) element;