Make KotlinType.isError extension instead of member
This commit is contained in:
-3
@@ -243,7 +243,4 @@ internal class NotNullTypeParameter(override val delegate: SimpleType) : CustomT
|
||||
override fun replaceAnnotations(newAnnotations: Annotations) = NotNullTypeParameter(delegate.replaceAnnotations(newAnnotations))
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean) =
|
||||
if (newNullability) delegate.makeNullableAsSpecified(true) else this
|
||||
|
||||
override val isError: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
+4
-7
@@ -23,10 +23,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.*
|
||||
|
||||
abstract class AbstractTypeAliasDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
@@ -53,9 +50,9 @@ abstract class AbstractTypeAliasDescriptor(
|
||||
// NB: it's ok to use underlyingType here, since referenced inner type aliases also capture type parameters.
|
||||
// Using expandedType looks "proper", but in fact will cause a recursion in expandedType resolution,
|
||||
// which will silently produce wrong result.
|
||||
TypeUtils.contains(underlyingType) {
|
||||
!it.isError && run {
|
||||
val constructorDescriptor = it.constructor.declarationDescriptor
|
||||
TypeUtils.contains(underlyingType) { type ->
|
||||
!type.isError && run {
|
||||
val constructorDescriptor = type.constructor.declarationDescriptor
|
||||
constructorDescriptor is TypeParameterDescriptor &&
|
||||
constructorDescriptor.containingDeclaration != this@AbstractTypeAliasDescriptor
|
||||
}
|
||||
|
||||
+2
-5
@@ -23,10 +23,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.types.ClassTypeConstructorImpl;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -126,7 +123,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase {
|
||||
}
|
||||
|
||||
public void addSupertype(@NotNull KotlinType supertype) {
|
||||
assert !supertype.isError() : "Error types must be filtered out in DescriptorResolver";
|
||||
assert !KotlinTypeKt.isError(supertype) : "Error types must be filtered out in DescriptorResolver";
|
||||
if (TypeUtils.getClassDescriptor(supertype) != null) {
|
||||
// See the Errors.SUPERTYPE_NOT_A_CLASS_OR_INTERFACE
|
||||
supertypes.add(supertype);
|
||||
|
||||
+6
-2
@@ -19,12 +19,16 @@ package org.jetbrains.kotlin.descriptors.impl;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement;
|
||||
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.KotlinTypeKt;
|
||||
import org.jetbrains.kotlin.types.Variance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -126,7 +130,7 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor
|
||||
}
|
||||
|
||||
private void doAddUpperBound(KotlinType bound) {
|
||||
if (bound.isError()) return;
|
||||
if (KotlinTypeKt.isError(bound)) return;
|
||||
upperBounds.add(bound); // TODO : Duplicates?
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,7 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
|
||||
import java.util.*;
|
||||
@@ -449,7 +446,7 @@ public class DescriptorUtils {
|
||||
}
|
||||
|
||||
public static boolean shouldRecordInitializerForProperty(@NotNull VariableDescriptor variable, @NotNull KotlinType type) {
|
||||
if (variable.isVar() || type.isError()) return false;
|
||||
if (variable.isVar() || KotlinTypeKt.isError(type)) return false;
|
||||
|
||||
if (TypeUtils.acceptsNullable(type)) return true;
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.FlexibleTypesKt;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.KotlinTypeKt;
|
||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeCheckerImpl;
|
||||
@@ -270,7 +271,7 @@ public class OverridingUtil {
|
||||
KotlinType subReturnType = subDescriptor.getReturnType();
|
||||
|
||||
if (superReturnType != null && subReturnType != null) {
|
||||
boolean bothErrors = subReturnType.isError() && superReturnType.isError();
|
||||
boolean bothErrors = KotlinTypeKt.isError(subReturnType) && KotlinTypeKt.isError(superReturnType);
|
||||
if (!bothErrors && !typeChecker.isSubtypeOf(subReturnType, superReturnType)) {
|
||||
return OverrideCompatibilityInfo.conflict("Return type mismatch");
|
||||
}
|
||||
@@ -353,7 +354,7 @@ public class OverridingUtil {
|
||||
@NotNull KotlinType typeInSub,
|
||||
@NotNull KotlinTypeChecker typeChecker
|
||||
) {
|
||||
boolean bothErrors = typeInSuper.isError() && typeInSub.isError();
|
||||
boolean bothErrors = KotlinTypeKt.isError(typeInSuper) && KotlinTypeKt.isError(typeInSub);
|
||||
return bothErrors || typeChecker.equalTypes(typeInSuper, typeInSub);
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -65,14 +65,12 @@ class CapturedType(
|
||||
override val isMarkedNullable: Boolean = false,
|
||||
override val annotations: Annotations = Annotations.EMPTY
|
||||
): SimpleType(), SubtypingRepresentatives {
|
||||
|
||||
override val arguments: List<TypeProjection>
|
||||
get() = listOf()
|
||||
|
||||
override val memberScope: MemberScope
|
||||
get() = ErrorUtils.createErrorScope(
|
||||
"No member resolution should be done on captured type, it used only during constraint system resolution", true)
|
||||
override val isError: Boolean
|
||||
get() = false
|
||||
|
||||
override val subTypeRepresentative: KotlinType
|
||||
get() = representative(OUT_VARIANCE, builtIns.nullableAnyType)
|
||||
|
||||
@@ -470,7 +470,7 @@ public class ErrorUtils {
|
||||
|
||||
public static boolean containsErrorType(@Nullable KotlinType type) {
|
||||
if (type == null) return false;
|
||||
if (type.isError()) return true;
|
||||
if (KotlinTypeKt.isError(type)) return true;
|
||||
for (TypeProjection projection : type.getArguments()) {
|
||||
if (!projection.isStarProjection() && containsErrorType(projection.getType())) return true;
|
||||
}
|
||||
@@ -486,7 +486,7 @@ public class ErrorUtils {
|
||||
return candidate instanceof ErrorClassDescriptor;
|
||||
}
|
||||
|
||||
private static class ErrorTypeImpl extends SimpleType {
|
||||
public static class ErrorTypeImpl extends SimpleType {
|
||||
private final TypeConstructor constructor;
|
||||
private final MemberScope memberScope;
|
||||
private final List<TypeProjection> arguments;
|
||||
@@ -531,17 +531,13 @@ public class ErrorUtils {
|
||||
return memberScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isError() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations getAnnotations() {
|
||||
return Annotations.Companion.getEMPTY();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return constructor.toString() + (arguments.isEmpty() ? "" : joinToString(arguments, ", ", "<", ">", -1, "...", null));
|
||||
|
||||
@@ -46,7 +46,6 @@ sealed class KotlinType : Annotated {
|
||||
abstract val arguments: List<TypeProjection>
|
||||
abstract val isMarkedNullable: Boolean
|
||||
abstract val memberScope: MemberScope
|
||||
abstract val isError: Boolean
|
||||
|
||||
abstract fun unwrap(): UnwrappedType
|
||||
|
||||
@@ -67,7 +66,7 @@ sealed class KotlinType : Annotated {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class WrappedType() : KotlinType() {
|
||||
abstract class WrappedType : KotlinType() {
|
||||
open fun isComputed(): Boolean = true
|
||||
protected abstract val delegate: KotlinType
|
||||
|
||||
@@ -76,7 +75,6 @@ abstract class WrappedType() : KotlinType() {
|
||||
override val arguments: List<TypeProjection> get() = delegate.arguments
|
||||
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
||||
override val memberScope: MemberScope get() = delegate.memberScope
|
||||
override val isError: Boolean get() = delegate.isError
|
||||
|
||||
override final fun unwrap(): UnwrappedType {
|
||||
var result = delegate
|
||||
@@ -156,8 +154,13 @@ abstract class FlexibleType(val lowerBound: SimpleType, val upperBound: SimpleTy
|
||||
override val arguments: List<TypeProjection> get() = delegate.arguments
|
||||
override val isMarkedNullable: Boolean get() = delegate.isMarkedNullable
|
||||
override val memberScope: MemberScope get() = delegate.memberScope
|
||||
override val isError: Boolean get() = delegate.isError // todo should be false?
|
||||
|
||||
override fun toString(): String = DescriptorRenderer.DEBUG_TEXT.renderType(this)
|
||||
}
|
||||
|
||||
val KotlinType.isError: Boolean
|
||||
get() {
|
||||
val unwrapped = unwrap()
|
||||
return unwrapped is ErrorUtils.ErrorTypeImpl ||
|
||||
(unwrapped is FlexibleType && unwrapped.delegate is ErrorUtils.ErrorTypeImpl)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
@@ -75,15 +74,15 @@ private class SimpleTypeImpl(
|
||||
override val isMarkedNullable: Boolean,
|
||||
override val memberScope: MemberScope
|
||||
) : SimpleType() {
|
||||
override fun replaceAnnotations(newAnnotations: Annotations) = SimpleTypeImpl(newAnnotations, constructor, arguments, isMarkedNullable, memberScope)
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean) = SimpleTypeImpl(annotations, constructor, arguments, newNullability, memberScope)
|
||||
override fun replaceAnnotations(newAnnotations: Annotations) =
|
||||
SimpleTypeImpl(newAnnotations, constructor, arguments, isMarkedNullable, memberScope)
|
||||
|
||||
override val isError: Boolean
|
||||
get() = false
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean) =
|
||||
SimpleTypeImpl(annotations, constructor, arguments, newNullability, memberScope)
|
||||
|
||||
init {
|
||||
if (memberScope is ErrorUtils.ErrorScope) {
|
||||
throw IllegalStateException("SimpleTypeImpl should not be created for error type: $memberScope\n$constructor")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,6 @@ class AbbreviatedType(override val delegate: SimpleType, val abbreviation: Simpl
|
||||
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean)
|
||||
= AbbreviatedType(delegate.makeNullableAsSpecified(newNullability), abbreviation.makeNullableAsSpecified(newNullability))
|
||||
|
||||
override val isError: Boolean get() = false
|
||||
}
|
||||
|
||||
fun KotlinType.getAbbreviatedType(): AbbreviatedType? = unwrap() as? AbbreviatedType
|
||||
@@ -56,4 +54,4 @@ class LazyWrappedType(storageManager: StorageManager, computation: () -> KotlinT
|
||||
override val delegate: KotlinType get() = lazyValue()
|
||||
|
||||
override fun isComputed(): Boolean = lazyValue.isComputed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class TypeSubstitutor {
|
||||
return new TypeProjectionImpl(substitutedProjectionKind, substitutedFlexibleType);
|
||||
}
|
||||
|
||||
if (KotlinBuiltIns.isNothing(type) || type.isError()) return originalProjection;
|
||||
if (KotlinBuiltIns.isNothing(type) || KotlinTypeKt.isError(type)) return originalProjection;
|
||||
|
||||
if (replacement != null) {
|
||||
VarianceConflictType varianceConflict = conflictType(originalProjectionKind, replacement.getProjectionKind());
|
||||
|
||||
@@ -49,11 +49,6 @@ public class TypeUtils {
|
||||
throw new IllegalStateException(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isError() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleType replaceAnnotations(@NotNull Annotations newAnnotations) {
|
||||
@@ -66,6 +61,7 @@ public class TypeUtils {
|
||||
throw new IllegalStateException(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
@@ -444,7 +440,7 @@ public class TypeUtils {
|
||||
@NotNull IntegerValueTypeConstructor numberValueTypeConstructor,
|
||||
@NotNull KotlinType expectedType
|
||||
) {
|
||||
if (noExpectedType(expectedType) || expectedType.isError()) {
|
||||
if (noExpectedType(expectedType) || KotlinTypeKt.isError(expectedType)) {
|
||||
return getDefaultPrimitiveNumberType(numberValueTypeConstructor);
|
||||
}
|
||||
for (KotlinType primitiveNumberType : numberValueTypeConstructor.getSupertypes()) {
|
||||
|
||||
@@ -86,13 +86,13 @@ class NewCapturedType(
|
||||
override val annotations: Annotations = Annotations.EMPTY,
|
||||
override val isMarkedNullable: Boolean = false
|
||||
): SimpleType() {
|
||||
|
||||
constructor(captureStatus: CaptureStatus, lowerType: UnwrappedType?, projection: TypeProjection): this(captureStatus, NewCapturedTypeConstructor(projection), lowerType)
|
||||
constructor(captureStatus: CaptureStatus, lowerType: UnwrappedType?, projection: TypeProjection) :
|
||||
this(captureStatus, NewCapturedTypeConstructor(projection), lowerType)
|
||||
|
||||
override val arguments: List<TypeProjection> get() = listOf()
|
||||
|
||||
override val memberScope: MemberScope // todo what about foo().bar() where foo() return captured type?
|
||||
get() = ErrorUtils.createErrorScope("No member resolution should be done on captured type!", true)
|
||||
override val isError: Boolean get() = false
|
||||
|
||||
override fun replaceAnnotations(newAnnotations: Annotations) =
|
||||
NewCapturedType(captureStatus, constructor, lowerType, newAnnotations, isMarkedNullable)
|
||||
|
||||
@@ -65,7 +65,8 @@ public class TypeCheckingProcedure {
|
||||
if (type1 == type2) return true;
|
||||
if (FlexibleTypesKt.isFlexible(type1)) {
|
||||
if (FlexibleTypesKt.isFlexible(type2)) {
|
||||
return !type1.isError() && !type2.isError() && isSubtypeOf(type1, type2) && isSubtypeOf(type2, type1);
|
||||
return !KotlinTypeKt.isError(type1) && !KotlinTypeKt.isError(type2) &&
|
||||
isSubtypeOf(type1, type2) && isSubtypeOf(type2, type1);
|
||||
}
|
||||
return heterogeneousEquivalence(type2, type1);
|
||||
}
|
||||
@@ -194,7 +195,7 @@ public class TypeCheckingProcedure {
|
||||
}
|
||||
|
||||
private boolean isSubtypeOfForRepresentatives(KotlinType subtype, KotlinType supertype) {
|
||||
if (subtype.isError() || supertype.isError()) {
|
||||
if (KotlinTypeKt.isError(subtype) || KotlinTypeKt.isError(supertype)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -239,7 +240,7 @@ public class TypeCheckingProcedure {
|
||||
|
||||
if (capture(subArgument, superArgument, parameter)) continue;
|
||||
|
||||
boolean argumentIsErrorType = subArgument.getType().isError() || superArgument.getType().isError();
|
||||
boolean argumentIsErrorType = KotlinTypeKt.isError(subArgument.getType()) || KotlinTypeKt.isError(superArgument.getType());
|
||||
if (!argumentIsErrorType && parameter.getVariance() == INVARIANT &&
|
||||
subArgument.getProjectionKind() == INVARIANT && superArgument.getProjectionKind() == INVARIANT) {
|
||||
if (!constraints.assertEqualTypes(subArgument.getType(), superArgument.getType(), this)) return false;
|
||||
|
||||
+1
-4
@@ -27,10 +27,7 @@ import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErr
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.asSimpleType
|
||||
import org.jetbrains.kotlin.types.*
|
||||
|
||||
interface DeserializedMemberDescriptor : MemberDescriptor {
|
||||
val proto: MessageLite
|
||||
|
||||
Reference in New Issue
Block a user