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
@@ -216,7 +216,7 @@ public abstract class AnnotationCodegen {
private static boolean isBareTypeParameterWithNullableUpperBound(@NotNull JetType type) {
ClassifierDescriptor classifier = type.getConstructor().getDeclarationDescriptor();
return !type.isNullable() && classifier instanceof TypeParameterDescriptor && TypeUtils.hasNullableSuperType(type);
return !type.isMarkedNullable() && classifier instanceof TypeParameterDescriptor && TypeUtils.hasNullableSuperType(type);
}
public void generateAnnotationDefaultValue(@NotNull CompileTimeConstant value, @NotNull JetType expectedType) {
@@ -3863,7 +3863,7 @@ The "returned" value of try expression with no finally is either the last expres
if (leaveExpressionOnStack) {
v.dup();
}
if (jetType.isNullable()) {
if (jetType.isMarkedNullable()) {
Label nope = new Label();
Label end = new Label();
@@ -25,7 +25,6 @@ import com.intellij.util.containers.ContainerUtil;
import kotlin.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.backend.common.CodegenUtil;
import org.jetbrains.jet.codegen.binding.CodegenBinding;
import org.jetbrains.jet.codegen.bridges.Bridge;
import org.jetbrains.jet.codegen.bridges.BridgesPackage;
@@ -71,7 +70,6 @@ import static org.jetbrains.jet.codegen.JvmSerializationBindings.*;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.DECLARATION;
import static org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils.callableDescriptorToDeclaration;
import static org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils.classDescriptorToDeclaration;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isFunctionLiteral;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait;
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
@@ -228,7 +226,7 @@ public class FunctionCodegen extends ParentCodegenAware {
if (kind == JvmMethodParameterKind.VALUE) {
ValueParameterDescriptor descriptor = descriptors.next();
name = descriptor.getName().asString();
nullableType = descriptor.getType().isNullable();
nullableType = descriptor.getType().isMarkedNullable();
}
else {
String lowercaseKind = kind.name().toLowerCase();
@@ -241,7 +239,7 @@ public class FunctionCodegen extends ParentCodegenAware {
if (kind == JvmMethodParameterKind.RECEIVER) {
ReceiverParameterDescriptor receiver = functionDescriptor.getExtensionReceiverParameter();
nullableType = receiver == null || receiver.getType().isNullable();
nullableType = receiver == null || receiver.getType().isMarkedNullable();
}
else {
nullableType = true;
@@ -285,7 +285,7 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
private static boolean skipDefaultValue(@NotNull PropertyDescriptor propertyDescriptor, Object value, @NotNull Type type) {
if (isPrimitive(type)) {
if (!propertyDescriptor.getType().isNullable() && value instanceof Number) {
if (!propertyDescriptor.getType().isMarkedNullable() && value instanceof Number) {
if (type == Type.INT_TYPE && ((Number) value).intValue() == 0) {
return true;
}
@@ -54,11 +54,11 @@ public class RangeCodegenUtil {
private RangeCodegenUtil() {}
public static boolean isRange(JetType rangeType) {
return !rangeType.isNullable() && getPrimitiveRangeElementType(rangeType) != null;
return !rangeType.isMarkedNullable() && getPrimitiveRangeElementType(rangeType) != null;
}
public static boolean isProgression(JetType rangeType) {
return !rangeType.isNullable() && getPrimitiveProgressionElementType(rangeType) != null;
return !rangeType.isMarkedNullable() && getPrimitiveProgressionElementType(rangeType) != null;
}
@Nullable
@@ -64,7 +64,7 @@ class PropagationHeuristics {
JetTypeImpl betterTypeInSuper = new JetTypeImpl(
arrayTypeFromSuper.getAnnotations(),
arrayTypeFromSuper.getConstructor(),
arrayTypeFromSuper.isNullable(),
arrayTypeFromSuper.isMarkedNullable(),
Arrays.asList(new TypeProjectionImpl(Variance.OUT_VARIANCE, elementTypeInSuper)),
JetScope.Empty.INSTANCE$);
@@ -78,7 +78,7 @@ public class SingleAbstractMethodUtils {
return new JetTypeImpl(
functionType.getAnnotations(),
functionType.getConstructor(),
functionType.isNullable(),
functionType.isMarkedNullable(),
arguments,
((ClassDescriptor) classifier).getMemberScope(arguments)
);
@@ -106,7 +106,7 @@ public class SingleAbstractMethodUtils {
return LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(fixedProjections, TypeUtils.makeNullable(fixedProjections));
}
return TypeUtils.makeNullableAsSpecified(fixedProjections, !isSamConstructor && samType.isNullable());
return TypeUtils.makeNullableAsSpecified(fixedProjections, !isSamConstructor && samType.isMarkedNullable());
}
}
return null;
@@ -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;