Renamed JetType.isNullable() to isMarkedNullable()
This commit is contained in:
@@ -216,7 +216,7 @@ public abstract class AnnotationCodegen {
|
|||||||
|
|
||||||
private static boolean isBareTypeParameterWithNullableUpperBound(@NotNull JetType type) {
|
private static boolean isBareTypeParameterWithNullableUpperBound(@NotNull JetType type) {
|
||||||
ClassifierDescriptor classifier = type.getConstructor().getDeclarationDescriptor();
|
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) {
|
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) {
|
if (leaveExpressionOnStack) {
|
||||||
v.dup();
|
v.dup();
|
||||||
}
|
}
|
||||||
if (jetType.isNullable()) {
|
if (jetType.isMarkedNullable()) {
|
||||||
Label nope = new Label();
|
Label nope = new Label();
|
||||||
Label end = new Label();
|
Label end = new Label();
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import com.intellij.util.containers.ContainerUtil;
|
|||||||
import kotlin.Function1;
|
import kotlin.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.backend.common.CodegenUtil;
|
|
||||||
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
||||||
import org.jetbrains.jet.codegen.bridges.Bridge;
|
import org.jetbrains.jet.codegen.bridges.Bridge;
|
||||||
import org.jetbrains.jet.codegen.bridges.BridgesPackage;
|
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.codegen.binding.CodegenBinding.isLocalNamedFun;
|
||||||
import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.DECLARATION;
|
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.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.isFunctionLiteral;
|
||||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait;
|
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||||
@@ -228,7 +226,7 @@ public class FunctionCodegen extends ParentCodegenAware {
|
|||||||
if (kind == JvmMethodParameterKind.VALUE) {
|
if (kind == JvmMethodParameterKind.VALUE) {
|
||||||
ValueParameterDescriptor descriptor = descriptors.next();
|
ValueParameterDescriptor descriptor = descriptors.next();
|
||||||
name = descriptor.getName().asString();
|
name = descriptor.getName().asString();
|
||||||
nullableType = descriptor.getType().isNullable();
|
nullableType = descriptor.getType().isMarkedNullable();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String lowercaseKind = kind.name().toLowerCase();
|
String lowercaseKind = kind.name().toLowerCase();
|
||||||
@@ -241,7 +239,7 @@ public class FunctionCodegen extends ParentCodegenAware {
|
|||||||
|
|
||||||
if (kind == JvmMethodParameterKind.RECEIVER) {
|
if (kind == JvmMethodParameterKind.RECEIVER) {
|
||||||
ReceiverParameterDescriptor receiver = functionDescriptor.getExtensionReceiverParameter();
|
ReceiverParameterDescriptor receiver = functionDescriptor.getExtensionReceiverParameter();
|
||||||
nullableType = receiver == null || receiver.getType().isNullable();
|
nullableType = receiver == null || receiver.getType().isMarkedNullable();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nullableType = true;
|
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) {
|
private static boolean skipDefaultValue(@NotNull PropertyDescriptor propertyDescriptor, Object value, @NotNull Type type) {
|
||||||
if (isPrimitive(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) {
|
if (type == Type.INT_TYPE && ((Number) value).intValue() == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,11 +54,11 @@ public class RangeCodegenUtil {
|
|||||||
private RangeCodegenUtil() {}
|
private RangeCodegenUtil() {}
|
||||||
|
|
||||||
public static boolean isRange(JetType rangeType) {
|
public static boolean isRange(JetType rangeType) {
|
||||||
return !rangeType.isNullable() && getPrimitiveRangeElementType(rangeType) != null;
|
return !rangeType.isMarkedNullable() && getPrimitiveRangeElementType(rangeType) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isProgression(JetType rangeType) {
|
public static boolean isProgression(JetType rangeType) {
|
||||||
return !rangeType.isNullable() && getPrimitiveProgressionElementType(rangeType) != null;
|
return !rangeType.isMarkedNullable() && getPrimitiveProgressionElementType(rangeType) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ class PropagationHeuristics {
|
|||||||
JetTypeImpl betterTypeInSuper = new JetTypeImpl(
|
JetTypeImpl betterTypeInSuper = new JetTypeImpl(
|
||||||
arrayTypeFromSuper.getAnnotations(),
|
arrayTypeFromSuper.getAnnotations(),
|
||||||
arrayTypeFromSuper.getConstructor(),
|
arrayTypeFromSuper.getConstructor(),
|
||||||
arrayTypeFromSuper.isNullable(),
|
arrayTypeFromSuper.isMarkedNullable(),
|
||||||
Arrays.asList(new TypeProjectionImpl(Variance.OUT_VARIANCE, elementTypeInSuper)),
|
Arrays.asList(new TypeProjectionImpl(Variance.OUT_VARIANCE, elementTypeInSuper)),
|
||||||
JetScope.Empty.INSTANCE$);
|
JetScope.Empty.INSTANCE$);
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -78,7 +78,7 @@ public class SingleAbstractMethodUtils {
|
|||||||
return new JetTypeImpl(
|
return new JetTypeImpl(
|
||||||
functionType.getAnnotations(),
|
functionType.getAnnotations(),
|
||||||
functionType.getConstructor(),
|
functionType.getConstructor(),
|
||||||
functionType.isNullable(),
|
functionType.isMarkedNullable(),
|
||||||
arguments,
|
arguments,
|
||||||
((ClassDescriptor) classifier).getMemberScope(arguments)
|
((ClassDescriptor) classifier).getMemberScope(arguments)
|
||||||
);
|
);
|
||||||
@@ -106,7 +106,7 @@ public class SingleAbstractMethodUtils {
|
|||||||
return LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(fixedProjections, TypeUtils.makeNullable(fixedProjections));
|
return LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(fixedProjections, TypeUtils.makeNullable(fixedProjections));
|
||||||
}
|
}
|
||||||
|
|
||||||
return TypeUtils.makeNullableAsSpecified(fixedProjections, !isSamConstructor && samType.isNullable());
|
return TypeUtils.makeNullableAsSpecified(fixedProjections, !isSamConstructor && samType.isMarkedNullable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public fun or(predicates: Collection<TypePredicate>): TypePredicate? =
|
|||||||
|
|
||||||
fun JetType.getSubtypesPredicate(): TypePredicate {
|
fun JetType.getSubtypesPredicate(): TypePredicate {
|
||||||
return when {
|
return when {
|
||||||
KotlinBuiltIns.isAnyOrNullableAny(this) && isNullable() -> AllTypes
|
KotlinBuiltIns.isAnyOrNullableAny(this) && isMarkedNullable() -> AllTypes
|
||||||
TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, this) -> AllSubtypes(this)
|
TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, this) -> AllSubtypes(this)
|
||||||
else -> SingleType(this)
|
else -> SingleType(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class CompileTimeConstantUtils {
|
|||||||
JetType parameterType = parameterDescriptor.getType();
|
JetType parameterType = parameterDescriptor.getType();
|
||||||
JetTypeReference typeReference = parameter.getTypeReference();
|
JetTypeReference typeReference = parameter.getTypeReference();
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
if (parameterType.isNullable()) {
|
if (parameterType.isMarkedNullable()) {
|
||||||
trace.report(NULLABLE_TYPE_OF_ANNOTATION_MEMBER.on(typeReference));
|
trace.report(NULLABLE_TYPE_OF_ANNOTATION_MEMBER.on(typeReference));
|
||||||
}
|
}
|
||||||
else if (!isAcceptableTypeForAnnotationParameter(parameterType)) {
|
else if (!isAcceptableTypeForAnnotationParameter(parameterType)) {
|
||||||
@@ -82,7 +82,7 @@ public class CompileTimeConstantUtils {
|
|||||||
List<TypeProjection> arguments = parameterType.getArguments();
|
List<TypeProjection> arguments = parameterType.getArguments();
|
||||||
if (arguments.size() == 1) {
|
if (arguments.size() == 1) {
|
||||||
JetType arrayType = arguments.get(0).getType();
|
JetType arrayType = arguments.get(0).getType();
|
||||||
if (arrayType.isNullable()) {
|
if (arrayType.isMarkedNullable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ClassDescriptor arrayTypeDescriptor = TypeUtils.getClassDescriptor(arrayType);
|
ClassDescriptor arrayTypeDescriptor = TypeUtils.getClassDescriptor(arrayType);
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class PossiblyBareType {
|
|||||||
|
|
||||||
public boolean isNullable() {
|
public boolean isNullable() {
|
||||||
if (isBare()) return isBareTypeNullable();
|
if (isBare()) return isBareTypeNullable();
|
||||||
return getActualType().isNullable();
|
return getActualType().isMarkedNullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PossiblyBareType makeNullable() {
|
public PossiblyBareType makeNullable() {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class CallResolverUtil {
|
|||||||
List<TypeProjection> newArguments = Lists.newArrayList();
|
List<TypeProjection> newArguments = Lists.newArrayList();
|
||||||
newArguments.addAll(arguments.subList(0, arguments.size() - 1));
|
newArguments.addAll(arguments.subList(0, arguments.size() - 1));
|
||||||
newArguments.add(new TypeProjectionImpl(Variance.INVARIANT, DONT_CARE));
|
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(
|
private static boolean hasReturnTypeDependentOnUninferredParams(
|
||||||
@@ -115,7 +115,7 @@ public class CallResolverUtil {
|
|||||||
fakeTypeArguments.add(new TypeProjectionImpl(typeProjection.getProjectionKind(), DONT_CARE));
|
fakeTypeArguments.add(new TypeProjectionImpl(typeProjection.getProjectionKind(), DONT_CARE));
|
||||||
}
|
}
|
||||||
return new JetTypeImpl(
|
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));
|
fakeTypeArguments, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -596,7 +596,7 @@ public class CandidateResolver {
|
|||||||
JetType receiverArgumentType = receiverArgument.getType();
|
JetType receiverArgumentType = receiverArgument.getType();
|
||||||
|
|
||||||
BindingContext bindingContext = trace.getBindingContext();
|
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)) {
|
if (!SmartCastUtils.canBeSmartCast(receiverParameter, receiverArgument, bindingContext, context.dataFlowInfo)) {
|
||||||
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
|
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
|
||||||
return UNSAFE_CALL_ERROR;
|
return UNSAFE_CALL_ERROR;
|
||||||
|
|||||||
+1
-1
@@ -222,7 +222,7 @@ public class InlineCallResolverExtension implements CallResolverExtension {
|
|||||||
JetType type = descriptor.getReturnType();
|
JetType type = descriptor.getReturnType();
|
||||||
return type != null &&
|
return type != null &&
|
||||||
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) &&
|
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) &&
|
||||||
!type.isNullable() &&
|
!type.isMarkedNullable() &&
|
||||||
!InlineUtil.hasNoinlineAnnotation(descriptor);
|
!InlineUtil.hasNoinlineAnnotation(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -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.resolve.scopes.receivers.*;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
import org.jetbrains.jet.lang.types.TypesPackage;
|
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||||
@@ -62,7 +61,7 @@ public class DataFlowValueFactory {
|
|||||||
if (receiverValue instanceof TransientReceiver || receiverValue instanceof ScriptReceiver) {
|
if (receiverValue instanceof TransientReceiver || receiverValue instanceof ScriptReceiver) {
|
||||||
// SCRIPT: smartcasts data flow
|
// SCRIPT: smartcasts data flow
|
||||||
JetType type = receiverValue.getType();
|
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);
|
return new DataFlowValue(receiverValue, type, nullable, Nullability.NOT_NULL);
|
||||||
}
|
}
|
||||||
else if (receiverValue instanceof ClassReceiver || receiverValue instanceof ExtensionReceiver) {
|
else if (receiverValue instanceof ClassReceiver || receiverValue instanceof ExtensionReceiver) {
|
||||||
|
|||||||
+2
-2
@@ -110,7 +110,7 @@ import static org.jetbrains.jet.lang.resolve.calls.smartcasts.Nullability.NOT_NU
|
|||||||
|
|
||||||
Set<JetType> enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1);
|
Set<JetType> enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1);
|
||||||
JetType originalType = key.getType();
|
JetType originalType = key.getType();
|
||||||
if (originalType.isNullable()) {
|
if (originalType.isMarkedNullable()) {
|
||||||
enrichedTypes.add(TypeUtils.makeNotNullable(originalType));
|
enrichedTypes.add(TypeUtils.makeNotNullable(originalType));
|
||||||
}
|
}
|
||||||
for (JetType type : types) {
|
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 (value.getType().equals(type)) return this;
|
||||||
if (getPossibleTypes(value).contains(type)) return this;
|
if (getPossibleTypes(value).contains(type)) return this;
|
||||||
ImmutableMap<DataFlowValue, Nullability> newNullabilityInfo =
|
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);
|
SetMultimap<DataFlowValue, JetType> newTypeInfo = ImmutableSetMultimap.of(value, type);
|
||||||
return new DelegatingDataFlowInfo(this, newNullabilityInfo, newTypeInfo);
|
return new DelegatingDataFlowInfo(this, newNullabilityInfo, newTypeInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -190,7 +190,7 @@ public class SmartCastUtils {
|
|||||||
@NotNull BindingContext bindingContext,
|
@NotNull BindingContext bindingContext,
|
||||||
@NotNull DataFlowInfo dataFlowInfo
|
@NotNull DataFlowInfo dataFlowInfo
|
||||||
) {
|
) {
|
||||||
if (!receiver.getType().isNullable()) return true;
|
if (!receiver.getType().isMarkedNullable()) return true;
|
||||||
|
|
||||||
List<JetType> smartCastVariants = getSmartCastVariants(receiver, bindingContext, dataFlowInfo);
|
List<JetType> smartCastVariants = getSmartCastVariants(receiver, bindingContext, dataFlowInfo);
|
||||||
for (JetType smartCastVariant : smartCastVariants) {
|
for (JetType smartCastVariant : smartCastVariants) {
|
||||||
|
|||||||
+1
-1
@@ -152,7 +152,7 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
|
|||||||
JetType type = parameter.getReturnType();
|
JetType type = parameter.getReturnType();
|
||||||
if (type != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)) {
|
if (type != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)) {
|
||||||
if (!InlineUtil.hasNoinlineAnnotation(parameter)) {
|
if (!InlineUtil.hasNoinlineAnnotation(parameter)) {
|
||||||
if (type.isNullable()) {
|
if (type.isMarkedNullable()) {
|
||||||
if (trace != null) {
|
if (trace != null) {
|
||||||
trace.report(Errors.NULLABLE_INLINE_PARAMETER.on(expression, expression, functionDescriptor));
|
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) {
|
public static boolean isCastErased(@NotNull JetType supertype, @NotNull JetType subtype, @NotNull JetTypeChecker typeChecker) {
|
||||||
// cast between T and T? is always OK
|
// 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);
|
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 '*'
|
* result = List<*>, some arguments were not inferred, replaced with '*'
|
||||||
*/
|
*/
|
||||||
public static TypeReconstructionResult findStaticallyKnownSubtype(@NotNull JetType supertype, @NotNull TypeConstructor subtypeConstructor) {
|
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>
|
// 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
|
// First, let's make List<T>, where T is a type variable
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class TypeUnifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Foo? ~ X? => Foo ~ X
|
// Foo? ~ X? => Foo ~ X
|
||||||
if (known.isNullable() && withVariables.isNullable()) {
|
if (known.isMarkedNullable() && withVariables.isMarkedNullable()) {
|
||||||
doUnify(
|
doUnify(
|
||||||
new TypeProjectionImpl(knownProjectionKind, TypeUtils.makeNotNullable(known)),
|
new TypeProjectionImpl(knownProjectionKind, TypeUtils.makeNotNullable(known)),
|
||||||
new TypeProjectionImpl(withVariablesProjectionKind, TypeUtils.makeNotNullable(withVariables)),
|
new TypeProjectionImpl(withVariablesProjectionKind, TypeUtils.makeNotNullable(withVariables)),
|
||||||
@@ -93,7 +93,7 @@ public class TypeUnifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Foo ~ X? => fail
|
// Foo ~ X? => fail
|
||||||
if (!known.isNullable() && withVariables.isNullable()) {
|
if (!known.isMarkedNullable() && withVariables.isMarkedNullable()) {
|
||||||
result.fail();
|
result.fail();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ public class TypeUnifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Foo? ~ Foo || in Foo ~ Foo || Foo ~ Bar
|
// Foo? ~ Foo || in Foo ~ Foo || Foo ~ Bar
|
||||||
boolean structuralMismatch = known.isNullable() != withVariables.isNullable()
|
boolean structuralMismatch = known.isMarkedNullable() != withVariables.isMarkedNullable()
|
||||||
|| knownProjectionKind != withVariablesProjectionKind
|
|| knownProjectionKind != withVariablesProjectionKind
|
||||||
|| !known.getConstructor().equals(withVariables.getConstructor());
|
|| !known.getConstructor().equals(withVariables.getConstructor());
|
||||||
if (structuralMismatch) {
|
if (structuralMismatch) {
|
||||||
|
|||||||
+1
-1
@@ -1079,7 +1079,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType rightType = rightTypeInfo.getType();
|
JetType rightType = rightTypeInfo.getType();
|
||||||
|
|
||||||
DataFlowInfo dataFlowInfo = resolvedCall.getDataFlowInfoForArguments().getResultInfo();
|
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());
|
DataFlowValue value = createDataFlowValue(left, leftType, context.trace.getBindingContext());
|
||||||
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
|
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -289,7 +289,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
context.trace.report(DYNAMIC_NOT_ALLOWED.on(typeReferenceAfterIs));
|
context.trace.report(DYNAMIC_NOT_ALLOWED.on(typeReferenceAfterIs));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!subjectType.isNullable() && targetType.isNullable()) {
|
if (!subjectType.isMarkedNullable() && targetType.isMarkedNullable()) {
|
||||||
JetTypeElement element = typeReferenceAfterIs.getTypeElement();
|
JetTypeElement element = typeReferenceAfterIs.getTypeElement();
|
||||||
assert element instanceof JetNullableType : "element must be instance of " + JetNullableType.class.getName();
|
assert element instanceof JetNullableType : "element must be instance of " + JetNullableType.class.getName();
|
||||||
JetNullableType nullableType = (JetNullableType) element;
|
JetNullableType nullableType = (JetNullableType) element;
|
||||||
|
|||||||
+1
-1
@@ -175,7 +175,7 @@ public abstract class LazyJavaMemberScope(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val jetType = c.typeResolver.transformJavaType(javaParameter.getType(), typeUsage)
|
val jetType = c.typeResolver.transformJavaType(javaParameter.getType(), typeUsage)
|
||||||
if (!PLATFORM_TYPES && jetType.isNullable() && c.hasNotNullAnnotation(javaParameter))
|
if (!PLATFORM_TYPES && jetType.isMarkedNullable() && c.hasNotNullAnnotation(javaParameter))
|
||||||
TypeUtils.makeNotNullable(jetType) to null
|
TypeUtils.makeNotNullable(jetType) to null
|
||||||
else
|
else
|
||||||
jetType to null
|
jetType to null
|
||||||
|
|||||||
+3
-3
@@ -259,7 +259,7 @@ class LazyJavaTypeResolver(
|
|||||||
when (classifier()) {
|
when (classifier()) {
|
||||||
is JavaTypeParameter -> {
|
is JavaTypeParameter -> {
|
||||||
if (isConstructorTypeParameter())
|
if (isConstructorTypeParameter())
|
||||||
getConstructorTypeParameterSubstitute().isNullable()
|
getConstructorTypeParameterSubstitute().isMarkedNullable()
|
||||||
else
|
else
|
||||||
attr.howThisTypeIsUsed !in setOf(TYPE_ARGUMENT, UPPER_BOUND, SUPERTYPE_ARGUMENT, SUPERTYPE)
|
attr.howThisTypeIsUsed !in setOf(TYPE_ARGUMENT, UPPER_BOUND, SUPERTYPE_ARGUMENT, SUPERTYPE)
|
||||||
}
|
}
|
||||||
@@ -269,7 +269,7 @@ class LazyJavaTypeResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isNullable(): Boolean = nullable()
|
override fun isMarkedNullable(): Boolean = nullable()
|
||||||
|
|
||||||
override fun getAnnotations() = attr.annotations
|
override fun getAnnotations() = attr.annotations
|
||||||
}
|
}
|
||||||
@@ -314,7 +314,7 @@ class LazyJavaTypeResolver(
|
|||||||
// Int! >< Int?
|
// Int! >< Int?
|
||||||
if (otherType.isFlexible()) return Specificity.Relation.DONT_KNOW
|
if (otherType.isFlexible()) return Specificity.Relation.DONT_KNOW
|
||||||
// Int? >< Int!
|
// Int? >< Int!
|
||||||
if (otherType.isNullable()) return Specificity.Relation.DONT_KNOW
|
if (otherType.isMarkedNullable()) return Specificity.Relation.DONT_KNOW
|
||||||
// Int! lessSpecific Int
|
// Int! lessSpecific Int
|
||||||
return Specificity.Relation.LESS_SPECIFIC
|
return Specificity.Relation.LESS_SPECIFIC
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ public class DescriptorUtils {
|
|||||||
public static boolean shouldRecordInitializerForProperty(@NotNull VariableDescriptor variable, @NotNull JetType type) {
|
public static boolean shouldRecordInitializerForProperty(@NotNull VariableDescriptor variable, @NotNull JetType type) {
|
||||||
if (variable.isVar() || type.isError()) return false;
|
if (variable.isVar() || type.isError()) return false;
|
||||||
|
|
||||||
if (type instanceof LazyType || type.isNullable()) return true;
|
if (type instanceof LazyType || type.isMarkedNullable()) return true;
|
||||||
|
|
||||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||||
return KotlinBuiltIns.isPrimitiveType(type) ||
|
return KotlinBuiltIns.isPrimitiveType(type) ||
|
||||||
|
|||||||
+1
-1
@@ -433,7 +433,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
TypeBoundsImpl typeBounds = getTypeBounds(parameterType);
|
TypeBoundsImpl typeBounds = getTypeBounds(parameterType);
|
||||||
assert typeBounds != null : "constraint should be generated only for type variables";
|
assert typeBounds != null : "constraint should be generated only for type variables";
|
||||||
|
|
||||||
if (!parameterType.isNullable() || !constrainingType.isNullable()) {
|
if (!parameterType.isMarkedNullable() || !constrainingType.isMarkedNullable()) {
|
||||||
typeBounds.addBound(boundKind, constrainingType, constraintPosition);
|
typeBounds.addBound(boundKind, constrainingType, constraintPosition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public abstract class AbstractJetType implements JetType {
|
|||||||
public final int hashCode() {
|
public final int hashCode() {
|
||||||
int result = getConstructor().hashCode();
|
int result = getConstructor().hashCode();
|
||||||
result = 31 * result + getArguments().hashCode();
|
result = 31 * result + getArguments().hashCode();
|
||||||
result = 31 * result + (isNullable() ? 1 : 0);
|
result = 31 * result + (isMarkedNullable() ? 1 : 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,13 +49,13 @@ public abstract class AbstractJetType implements JetType {
|
|||||||
|
|
||||||
JetType type = (JetType) obj;
|
JetType type = (JetType) obj;
|
||||||
|
|
||||||
return isNullable() == type.isNullable() && JetTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(this, type);
|
return isMarkedNullable() == type.isMarkedNullable() && JetTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(this, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
List<TypeProjection> arguments = getArguments();
|
List<TypeProjection> arguments = getArguments();
|
||||||
return getConstructor() + (arguments.isEmpty() ? "" : "<" + argumentsToString(arguments) + ">") + (isNullable() ? "?" : "");
|
return getConstructor() + (arguments.isEmpty() ? "" : "<" + argumentsToString(arguments) + ">") + (isMarkedNullable() ? "?" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StringBuilder argumentsToString(List<TypeProjection> arguments) {
|
private static StringBuilder argumentsToString(List<TypeProjection> arguments) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public abstract class AbstractLazyType(storageManager: StorageManager) : Abstrac
|
|||||||
|
|
||||||
protected abstract fun computeMemberScope(): JetScope
|
protected abstract fun computeMemberScope(): JetScope
|
||||||
|
|
||||||
override fun isNullable() = false
|
override fun isMarkedNullable() = false
|
||||||
|
|
||||||
override fun isError() = getConstructor().getDeclarationDescriptor()?.let { d -> ErrorUtils.isError(d) } ?: false
|
override fun isError() = getConstructor().getDeclarationDescriptor()?.let { d -> ErrorUtils.isError(d) } ?: false
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class CommonSupertypes {
|
|||||||
if (type.isError()) {
|
if (type.isError()) {
|
||||||
return ErrorUtils.createErrorType("Supertype of error type " + type);
|
return ErrorUtils.createErrorType("Supertype of error type " + type);
|
||||||
}
|
}
|
||||||
nullable |= type.isNullable();
|
nullable |= type.isMarkedNullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Everything deleted => it's Nothing or Nothing?
|
// Everything deleted => it's Nothing or Nothing?
|
||||||
@@ -220,7 +220,7 @@ public class CommonSupertypes {
|
|||||||
|
|
||||||
boolean nullable = false;
|
boolean nullable = false;
|
||||||
for (JetType type : types) {
|
for (JetType type : types) {
|
||||||
nullable |= type.isNullable();
|
nullable |= type.isMarkedNullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : attributes?
|
// TODO : attributes?
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ public abstract class DelegatingType implements JetType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNullable() {
|
public boolean isMarkedNullable() {
|
||||||
return getDelegate().isNullable();
|
return getDelegate().isMarkedNullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ public class ErrorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNullable() {
|
public boolean isMarkedNullable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public interface JetType extends Annotated {
|
|||||||
@ReadOnly
|
@ReadOnly
|
||||||
List<TypeProjection> getArguments();
|
List<TypeProjection> getArguments();
|
||||||
|
|
||||||
boolean isNullable();
|
boolean isMarkedNullable();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
JetScope getMemberScope();
|
JetScope getMemberScope();
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public final class JetTypeImpl extends AbstractJetType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNullable() {
|
public boolean isMarkedNullable() {
|
||||||
return nullable;
|
return nullable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public class TypeSubstitutor {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// this is a simple type T or T?: if it's T, we should just take replacement, if T? - we make replacement nullable
|
// this is a simple type T or T?: if it's T, we should just take replacement, if T? - we make replacement nullable
|
||||||
substitutedType = type.isNullable() ? TypeUtils.makeNullable(replacement.getType()) : replacement.getType();
|
substitutedType = type.isMarkedNullable() ? TypeUtils.makeNullable(replacement.getType()) : replacement.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
Variance resultingProjectionKind = combine(originalProjectionKind, replacement.getProjectionKind());
|
Variance resultingProjectionKind = combine(originalProjectionKind, replacement.getProjectionKind());
|
||||||
@@ -231,7 +231,7 @@ public class TypeSubstitutor {
|
|||||||
};
|
};
|
||||||
JetType substitutedType = new JetTypeImpl(type.getAnnotations(), // Old annotations. This is questionable
|
JetType substitutedType = new JetTypeImpl(type.getAnnotations(), // Old annotations. This is questionable
|
||||||
type.getConstructor(), // The same constructor
|
type.getConstructor(), // The same constructor
|
||||||
type.isNullable(), // Same nullability
|
type.isMarkedNullable(), // Same nullability
|
||||||
substitutedArguments,
|
substitutedArguments,
|
||||||
new SubstitutingScope(type.getMemberScope(), create(substitutionFilteringTypeParameters)));
|
new SubstitutingScope(type.getMemberScope(), create(substitutionFilteringTypeParameters)));
|
||||||
return new TypeProjectionImpl(projectionKind, substitutedType);
|
return new TypeProjectionImpl(projectionKind, substitutedType);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNullable() {
|
public boolean isMarkedNullable() {
|
||||||
throw new IllegalStateException(name);
|
throw new IllegalStateException(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// checking to preserve laziness
|
// checking to preserve laziness
|
||||||
if (!(type instanceof LazyType) && type.isNullable() == nullable) {
|
if (!(type instanceof LazyType) && type.isMarkedNullable() == nullable) {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ public class TypeUtils {
|
|||||||
List<JetType> nullabilityStripped = new ArrayList<JetType>(types.size());
|
List<JetType> nullabilityStripped = new ArrayList<JetType>(types.size());
|
||||||
for (JetType type : types) {
|
for (JetType type : types) {
|
||||||
nothingTypePresent |= KotlinBuiltIns.isNothingOrNullableNothing(type);
|
nothingTypePresent |= KotlinBuiltIns.isNothingOrNullableNothing(type);
|
||||||
allNullable &= type.isNullable();
|
allNullable &= type.isMarkedNullable();
|
||||||
nullabilityStripped.add(makeNotNullable(type));
|
nullabilityStripped.add(makeNotNullable(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canHaveSubtypes(JetTypeChecker typeChecker, JetType type) {
|
public static boolean canHaveSubtypes(JetTypeChecker typeChecker, JetType type) {
|
||||||
if (type.isNullable()) {
|
if (type.isMarkedNullable()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!type.getConstructor().isFinal()) {
|
if (!type.getConstructor().isFinal()) {
|
||||||
@@ -401,7 +401,7 @@ public class TypeUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<JetType> getImmediateSupertypes(@NotNull JetType type) {
|
public static List<JetType> getImmediateSupertypes(@NotNull JetType type) {
|
||||||
boolean isNullable = type.isNullable();
|
boolean isNullable = type.isMarkedNullable();
|
||||||
TypeSubstitutor substitutor = TypeSubstitutor.create(type);
|
TypeSubstitutor substitutor = TypeSubstitutor.create(type);
|
||||||
Collection<JetType> originalSupertypes = type.getConstructor().getSupertypes();
|
Collection<JetType> originalSupertypes = type.getConstructor().getSupertypes();
|
||||||
List<JetType> result = new ArrayList<JetType>(originalSupertypes.size());
|
List<JetType> result = new ArrayList<JetType>(originalSupertypes.size());
|
||||||
@@ -434,7 +434,7 @@ public class TypeUtils {
|
|||||||
|
|
||||||
public static boolean hasNullableLowerBound(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
public static boolean hasNullableLowerBound(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
||||||
for (JetType bound : typeParameterDescriptor.getLowerBounds()) {
|
for (JetType bound : typeParameterDescriptor.getLowerBounds()) {
|
||||||
if (bound.isNullable()) {
|
if (bound.isMarkedNullable()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -446,7 +446,7 @@ public class TypeUtils {
|
|||||||
* @return true if a value of this type can be null
|
* @return true if a value of this type can be null
|
||||||
*/
|
*/
|
||||||
public static boolean isNullableType(@NotNull JetType type) {
|
public static boolean isNullableType(@NotNull JetType type) {
|
||||||
if (type.isNullable()) {
|
if (type.isMarkedNullable()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (TypesPackage.isFlexible(type) && isNullableType(TypesPackage.flexibility(type).getUpperBound())) {
|
if (TypesPackage.isFlexible(type) && isNullableType(TypesPackage.flexibility(type).getUpperBound())) {
|
||||||
@@ -465,7 +465,7 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (JetType supertype : getImmediateSupertypes(type)) {
|
for (JetType supertype : getImmediateSupertypes(type)) {
|
||||||
if (supertype.isNullable()) return true;
|
if (supertype.isMarkedNullable()) return true;
|
||||||
if (hasNullableSuperType(supertype)) return true;
|
if (hasNullableSuperType(supertype)) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,7 +775,7 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean isNullable();
|
public abstract boolean isMarkedNullable();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -802,7 +802,7 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNullable() {
|
public boolean isMarkedNullable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -814,7 +814,7 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNullable() {
|
public boolean isMarkedNullable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -79,11 +79,11 @@ public class TypeCheckingProcedure {
|
|||||||
return heterogeneousEquivalence(type1, type2);
|
return heterogeneousEquivalence(type1, type2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type1.isNullable() != type2.isNullable()) {
|
if (type1.isMarkedNullable() != type2.isMarkedNullable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type1.isNullable()) {
|
if (type1.isMarkedNullable()) {
|
||||||
// Then type2 is nullable, too (see the previous condition
|
// Then type2 is nullable, too (see the previous condition
|
||||||
return constraints.assertEqualTypes(TypeUtils.makeNotNullable(type1), TypeUtils.makeNotNullable(type2), this);
|
return constraints.assertEqualTypes(TypeUtils.makeNotNullable(type1), TypeUtils.makeNotNullable(type2), this);
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ public class TypeCheckingProcedure {
|
|||||||
if (subtype.isError() || supertype.isError()) {
|
if (subtype.isError() || supertype.isError()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!supertype.isNullable() && subtype.isNullable()) {
|
if (!supertype.isMarkedNullable() && subtype.isMarkedNullable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
subtype = TypeUtils.makeNotNullable(subtype);
|
subtype = TypeUtils.makeNotNullable(subtype);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public trait Approximation : TypeCapability {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Approximation.Info.assertNotNull(): Boolean {
|
fun Approximation.Info.assertNotNull(): Boolean {
|
||||||
return from.upperIfFlexible().isNullable() && !TypeUtils.isNullableType(to)
|
return from.upperIfFlexible().isMarkedNullable() && !TypeUtils.isNullableType(to)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun JetType.getApproximationTo(
|
public fun JetType.getApproximationTo(
|
||||||
@@ -161,9 +161,9 @@ public open class DelegatingFlexibleType protected (
|
|||||||
extraCapabilities)
|
extraCapabilities)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun computeIsNullable() = delegateType.isNullable()
|
override fun computeIsNullable() = delegateType.isMarkedNullable()
|
||||||
|
|
||||||
override fun isNullable(): Boolean = getCapability(javaClass<NullAwareness>())!!.computeIsNullable()
|
override fun isMarkedNullable(): Boolean = getCapability(javaClass<NullAwareness>())!!.computeIsNullable()
|
||||||
|
|
||||||
override fun approximateToExpectedType(expectedType: JetType, dataFlowExtras: Approximation.DataFlowExtras): Approximation.Info? {
|
override fun approximateToExpectedType(expectedType: JetType, dataFlowExtras: Approximation.DataFlowExtras): Approximation.Info? {
|
||||||
// val foo: Any? = foo() : Foo!
|
// val foo: Any? = foo() : Foo!
|
||||||
|
|||||||
@@ -750,7 +750,7 @@ public class KotlinBuiltIns {
|
|||||||
|
|
||||||
public static boolean isPrimitiveType(@NotNull JetType type) {
|
public static boolean isPrimitiveType(@NotNull JetType type) {
|
||||||
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||||
return !type.isNullable() && descriptor != null && FQ_NAMES.primitiveTypes.contains(DescriptorUtils.getFqName(descriptor));
|
return !type.isMarkedNullable() && descriptor != null && FQ_NAMES.primitiveTypes.contains(DescriptorUtils.getFqName(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
@@ -853,7 +853,7 @@ public class KotlinBuiltIns {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNotNullConstructedFromGivenClass(@NotNull JetType type, @NotNull FqNameUnsafe fqName) {
|
private static boolean isNotNullConstructedFromGivenClass(@NotNull JetType type, @NotNull FqNameUnsafe fqName) {
|
||||||
return !type.isNullable() && isConstructedFromGivenClass(type, fqName);
|
return !type.isMarkedNullable() && isConstructedFromGivenClass(type, fqName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) {
|
public static boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) {
|
||||||
@@ -867,12 +867,12 @@ public class KotlinBuiltIns {
|
|||||||
|
|
||||||
public static boolean isNothing(@NotNull JetType type) {
|
public static boolean isNothing(@NotNull JetType type) {
|
||||||
return isNothingOrNullableNothing(type)
|
return isNothingOrNullableNothing(type)
|
||||||
&& !type.isNullable();
|
&& !type.isMarkedNullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNullableNothing(@NotNull JetType type) {
|
public static boolean isNullableNothing(@NotNull JetType type) {
|
||||||
return isNothingOrNullableNothing(type)
|
return isNothingOrNullableNothing(type)
|
||||||
&& type.isNullable();
|
&& type.isMarkedNullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNothingOrNullableNothing(@NotNull JetType type) {
|
public static boolean isNothingOrNullableNothing(@NotNull JetType type) {
|
||||||
|
|||||||
@@ -445,7 +445,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
|||||||
sb.append(renderTypeName(type.getConstructor()));
|
sb.append(renderTypeName(type.getConstructor()));
|
||||||
}
|
}
|
||||||
sb.append(renderTypeArguments(type.getArguments()));
|
sb.append(renderTypeArguments(type.getArguments()));
|
||||||
if (type.isNullable()) {
|
if (type.isMarkedNullable()) {
|
||||||
sb.append("?");
|
sb.append("?");
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@@ -494,7 +494,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
|||||||
sb.append(") ").append(arrow()).append(" ");
|
sb.append(") ").append(arrow()).append(" ");
|
||||||
sb.append(renderNormalizedType(KotlinBuiltIns.getReturnTypeFromFunctionType(type)));
|
sb.append(renderNormalizedType(KotlinBuiltIns.getReturnTypeFromFunctionType(type)));
|
||||||
|
|
||||||
if (type.isNullable()) {
|
if (type.isMarkedNullable()) {
|
||||||
return "(" + sb + ")?";
|
return "(" + sb + ")?";
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|||||||
+1
-1
@@ -351,7 +351,7 @@ public class DescriptorSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// to avoid storing a default
|
// to avoid storing a default
|
||||||
if (type.isNullable()) {
|
if (type.isMarkedNullable()) {
|
||||||
builder.setNullable(true);
|
builder.setNullable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ class DeserializedType(
|
|||||||
|
|
||||||
override fun getArguments(): List<TypeProjection> = arguments
|
override fun getArguments(): List<TypeProjection> = arguments
|
||||||
|
|
||||||
override fun isNullable(): Boolean = typeProto.getNullable()
|
override fun isMarkedNullable(): Boolean = typeProto.getNullable()
|
||||||
|
|
||||||
private fun computeMemberScope(): JetScope =
|
private fun computeMemberScope(): JetScope =
|
||||||
if (isError()) {
|
if (isError()) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ fun CallableDescriptor.fuzzyExtensionReceiverType(): FuzzyType? {
|
|||||||
|
|
||||||
fun FuzzyType.makeNotNullable() = FuzzyType(type.makeNotNullable(), freeParameters)
|
fun FuzzyType.makeNotNullable() = FuzzyType(type.makeNotNullable(), freeParameters)
|
||||||
fun FuzzyType.makeNullable() = FuzzyType(type.makeNullable(), freeParameters)
|
fun FuzzyType.makeNullable() = FuzzyType(type.makeNullable(), freeParameters)
|
||||||
fun FuzzyType.isNullable() = type.isNullable()
|
fun FuzzyType.isNullable() = type.isMarkedNullable()
|
||||||
|
|
||||||
class FuzzyType(
|
class FuzzyType(
|
||||||
val type: JetType,
|
val type: JetType,
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true)
|
|||||||
return JetTypeImpl(
|
return JetTypeImpl(
|
||||||
jetType.getAnnotations(),
|
jetType.getAnnotations(),
|
||||||
jetType.getConstructor(),
|
jetType.getConstructor(),
|
||||||
jetType.isNullable(),
|
jetType.isMarkedNullable(),
|
||||||
jetType.getArguments().map { TypeProjectionImpl(it.getProjectionKind(), approximateFlexibleTypes(it.getType(), false)) },
|
jetType.getArguments().map { TypeProjectionImpl(it.getProjectionKind(), approximateFlexibleTypes(it.getType(), false)) },
|
||||||
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
|
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-2
@@ -134,8 +134,8 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
|||||||
JetTokens.MULTEQ -> if (functionName == "multAssign") "$leftText.multAssign($rightText)" else "$leftText = $leftText.mult($rightText)"
|
JetTokens.MULTEQ -> if (functionName == "multAssign") "$leftText.multAssign($rightText)" else "$leftText = $leftText.mult($rightText)"
|
||||||
JetTokens.DIVEQ -> if (functionName == "divAssign") "$leftText.divAssign($rightText)" else "$leftText = $leftText.div($rightText)"
|
JetTokens.DIVEQ -> if (functionName == "divAssign") "$leftText.divAssign($rightText)" else "$leftText = $leftText.div($rightText)"
|
||||||
JetTokens.PERCEQ -> if (functionName == "modAssign") "$leftText.modAssign($rightText)" else "$leftText = $leftText.mod($rightText)"
|
JetTokens.PERCEQ -> if (functionName == "modAssign") "$leftText.modAssign($rightText)" else "$leftText = $leftText.mod($rightText)"
|
||||||
JetTokens.EQEQ -> if (elemType?.isNullable() ?: true) "$leftText?.equals($rightText) ?: $rightText.identityEquals(null)" else "$leftText.equals($rightText)"
|
JetTokens.EQEQ -> if (elemType?.isMarkedNullable() ?: true) "$leftText?.equals($rightText) ?: $rightText.identityEquals(null)" else "$leftText.equals($rightText)"
|
||||||
JetTokens.EXCLEQ -> if (elemType?.isNullable() ?: true) "!($leftText?.equals($rightText) ?: $rightText.identityEquals(null))" else "!$leftText.equals($rightText)"
|
JetTokens.EXCLEQ -> if (elemType?.isMarkedNullable() ?: true) "!($leftText?.equals($rightText) ?: $rightText.identityEquals(null))" else "!$leftText.equals($rightText)"
|
||||||
JetTokens.GT -> "$leftText.compareTo($rightText) > 0"
|
JetTokens.GT -> "$leftText.compareTo($rightText) > 0"
|
||||||
JetTokens.LT -> "$leftText.compareTo($rightText) < 0"
|
JetTokens.LT -> "$leftText.compareTo($rightText) < 0"
|
||||||
JetTokens.GTEQ -> "$leftText.compareTo($rightText) >= 0"
|
JetTokens.GTEQ -> "$leftText.compareTo($rightText) >= 0"
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers;
|
|
||||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -186,7 +184,7 @@ public class CodeInsightUtils {
|
|||||||
|
|
||||||
public static String defaultInitializer(JetType type) {
|
public static String defaultInitializer(JetType type) {
|
||||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||||
if (type.isNullable()) {
|
if (type.isMarkedNullable()) {
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
else if (type.equals(builtIns.getIntType()) || type.equals(builtIns.getLongType()) ||
|
else if (type.equals(builtIns.getIntType()) || type.equals(builtIns.getLongType()) ||
|
||||||
|
|||||||
@@ -207,12 +207,12 @@ public class LookupElementFactory(
|
|||||||
private fun callableWeight(descriptor: DeclarationDescriptor): CallableWeight? {
|
private fun callableWeight(descriptor: DeclarationDescriptor): CallableWeight? {
|
||||||
if (descriptor !is CallableDescriptor) return null
|
if (descriptor !is CallableDescriptor) return null
|
||||||
|
|
||||||
val isReceiverNullable = receiverTypes.isNotEmpty() && receiverTypes.all { it.isNullable() }
|
val isReceiverNullable = receiverTypes.isNotEmpty() && receiverTypes.all { it.isMarkedNullable() }
|
||||||
val receiverParameter = descriptor.getExtensionReceiverParameter()
|
val receiverParameter = descriptor.getExtensionReceiverParameter()
|
||||||
|
|
||||||
if (receiverParameter != null) {
|
if (receiverParameter != null) {
|
||||||
val receiverParamType = receiverParameter.getType()
|
val receiverParamType = receiverParameter.getType()
|
||||||
return if (isReceiverNullable && !receiverParamType.isNullable())
|
return if (isReceiverNullable && !receiverParamType.isMarkedNullable())
|
||||||
CallableWeight.notApplicableReceiverNullable
|
CallableWeight.notApplicableReceiverNullable
|
||||||
else if (receiverTypes.any { TypeUtils.equalTypes(it, receiverParamType) })
|
else if (receiverTypes.any { TypeUtils.equalTypes(it, receiverParamType) })
|
||||||
CallableWeight.thisTypeExtension
|
CallableWeight.thisTypeExtension
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ object KeywordValues {
|
|||||||
|
|
||||||
collection.addLookupElements(null,
|
collection.addLookupElements(null,
|
||||||
expectedInfos,
|
expectedInfos,
|
||||||
{ info -> if (info.type.isNullable()) ExpectedInfoClassification.matches(TypeSubstitutor.EMPTY) else ExpectedInfoClassification.notMatches },
|
{ info -> if (info.type.isMarkedNullable()) ExpectedInfoClassification.matches(TypeSubstitutor.EMPTY) else ExpectedInfoClassification.notMatches },
|
||||||
{ LookupElementBuilder.create("null").bold().assignSmartCompletionPriority(SmartCompletionItemPriority.NULL) })
|
{ LookupElementBuilder.create("null").bold().assignSmartCompletionPriority(SmartCompletionItemPriority.NULL) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -41,6 +41,6 @@ public class JetSuggestVariableNameMacro extends BaseJetVariableMacro {
|
|||||||
@NotNull Project project,
|
@NotNull Project project,
|
||||||
@NotNull ExpressionTypingComponents components
|
@NotNull ExpressionTypingComponents components
|
||||||
) {
|
) {
|
||||||
return variableDescriptor.getType().isNullable();
|
return variableDescriptor.getType().isMarkedNullable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -54,7 +54,7 @@ private fun JetType.render(typeParameterNameMap: Map<TypeParameterDescriptor, St
|
|||||||
val arguments = getArguments().map { it.getType().render(typeParameterNameMap, fq) }
|
val arguments = getArguments().map { it.getType().render(typeParameterNameMap, fq) }
|
||||||
val typeString = getConstructor().getDeclarationDescriptor()!!.render(typeParameterNameMap, fq)
|
val typeString = getConstructor().getDeclarationDescriptor()!!.render(typeParameterNameMap, fq)
|
||||||
val typeArgumentString = if (arguments.notEmpty) arguments.joinToString(", ", "<", ">") else ""
|
val typeArgumentString = if (arguments.notEmpty) arguments.joinToString(", ", "<", ">") else ""
|
||||||
val nullifier = if (isNullable()) "?" else ""
|
val nullifier = if (isMarkedNullable()) "?" else ""
|
||||||
return "$typeString$typeArgumentString$nullifier"
|
return "$typeString$typeArgumentString$nullifier"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ private fun JetNamedDeclaration.guessType(context: BindingContext): Array<JetTyp
|
|||||||
private class JetTypeSubstitution(public val forType: JetType, public val byType: JetType)
|
private class JetTypeSubstitution(public val forType: JetType, public val byType: JetType)
|
||||||
|
|
||||||
private fun JetType.substitute(substitution: JetTypeSubstitution, variance: Variance): JetType {
|
private fun JetType.substitute(substitution: JetTypeSubstitution, variance: Variance): JetType {
|
||||||
val nullable = isNullable()
|
val nullable = isMarkedNullable()
|
||||||
val currentType = makeNotNullable()
|
val currentType = makeNotNullable()
|
||||||
|
|
||||||
if (when (variance) {
|
if (when (variance) {
|
||||||
@@ -218,7 +218,7 @@ private fun JetType.substitute(substitution: JetTypeSubstitution, variance: Vari
|
|||||||
val (projection, typeParameter) = pair
|
val (projection, typeParameter) = pair
|
||||||
TypeProjectionImpl(Variance.INVARIANT, projection.getType().substitute(substitution, typeParameter.getVariance()))
|
TypeProjectionImpl(Variance.INVARIANT, projection.getType().substitute(substitution, typeParameter.getVariance()))
|
||||||
}
|
}
|
||||||
return JetTypeImpl(getAnnotations(), getConstructor(), isNullable(), newArguments, getMemberScope())
|
return JetTypeImpl(getAnnotations(), getConstructor(), isMarkedNullable(), newArguments, getMemberScope())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ object CreateIteratorFunctionActionFactory : JetSingleIntentionActionFactory() {
|
|||||||
|
|
||||||
val returnJetTypeParameterType = TypeProjectionImpl(returnJetTypeParameterTypes[0])
|
val returnJetTypeParameterType = TypeProjectionImpl(returnJetTypeParameterTypes[0])
|
||||||
val returnJetTypeArguments = Collections.singletonList(returnJetTypeParameterType)
|
val returnJetTypeArguments = Collections.singletonList(returnJetTypeParameterType)
|
||||||
val newReturnJetType = JetTypeImpl(returnJetType.getAnnotations(), returnJetType.getConstructor(), returnJetType.isNullable(), returnJetTypeArguments, returnJetType.getMemberScope())
|
val newReturnJetType = JetTypeImpl(returnJetType.getAnnotations(), returnJetType.getConstructor(), returnJetType.isMarkedNullable(), returnJetTypeArguments, returnJetType.getMemberScope())
|
||||||
val returnType = TypeInfo(newReturnJetType, Variance.OUT_VARIANCE)
|
val returnType = TypeInfo(newReturnJetType, Variance.OUT_VARIANCE)
|
||||||
return CreateCallableFromUsageFix(forExpr, FunctionInfo("iterator", iterableType, returnType))
|
return CreateCallableFromUsageFix(forExpr, FunctionInfo("iterator", iterableType, returnType))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ public class JetPsiUnifier(
|
|||||||
if (type1 != null && type2 != null) {
|
if (type1 != null && type2 != null) {
|
||||||
if (TypeUtils.equalTypes(type1, type2)) return MATCHED
|
if (TypeUtils.equalTypes(type1, type2)) return MATCHED
|
||||||
|
|
||||||
if (type1.isNullable() != type2.isNullable()) return UNMATCHED
|
if (type1.isMarkedNullable() != type2.isMarkedNullable()) return UNMATCHED
|
||||||
if (!matchDescriptors(
|
if (!matchDescriptors(
|
||||||
type1.getConstructor().getDeclarationDescriptor(),
|
type1.getConstructor().getDeclarationDescriptor(),
|
||||||
type2.getConstructor().getDeclarationDescriptor())) return UNMATCHED
|
type2.getConstructor().getDeclarationDescriptor())) return UNMATCHED
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public final class PatternTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNullable(JetTypeReference typeReference) {
|
private boolean isNullable(JetTypeReference typeReference) {
|
||||||
return getTypeByReference(bindingContext(), typeReference).isNullable();
|
return getTypeByReference(bindingContext(), typeReference).isMarkedNullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+1
-1
@@ -90,7 +90,7 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JetType type = context().bindingContext().get(BindingContext.EXPRESSION_TYPE, entryExpression);
|
JetType type = context().bindingContext().get(BindingContext.EXPRESSION_TYPE, entryExpression);
|
||||||
if (type == null || type.isNullable()) {
|
if (type == null || type.isMarkedNullable()) {
|
||||||
append(TopLevelFIF.TO_STRING.apply((JsExpression) null, Collections.singletonList(translatedExpression), context()));
|
append(TopLevelFIF.TO_STRING.apply((JsExpression) null, Collections.singletonList(translatedExpression), context()));
|
||||||
}
|
}
|
||||||
else if (mustCallToString(type)) {
|
else if (mustCallToString(type)) {
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public final class UnaryOperationTranslator {
|
|||||||
JetExpression baseExpression = getBaseExpression(expression);
|
JetExpression baseExpression = getBaseExpression(expression);
|
||||||
JetType type = BindingContextUtils.getNotNull(context.bindingContext(), BindingContext.EXPRESSION_TYPE, baseExpression);
|
JetType type = BindingContextUtils.getNotNull(context.bindingContext(), BindingContext.EXPRESSION_TYPE, baseExpression);
|
||||||
JsExpression translatedExpression = translateAsExpression(baseExpression, context);
|
JsExpression translatedExpression = translateAsExpression(baseExpression, context);
|
||||||
return type.isNullable() ? sure(translatedExpression, context) : translatedExpression;
|
return type.isMarkedNullable() ? sure(translatedExpression, context) : translatedExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operationToken == JetTokens.MINUS) {
|
if (operationToken == JetTokens.MINUS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user