Make upper bounds of type parameter a list instead of a set
The same for lower bounds, also refactor type parameter implementations
This commit is contained in:
+2
-5
@@ -39,10 +39,7 @@ import org.jetbrains.kotlin.types.Variance;
|
|||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.load.java.components.TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT;
|
import static org.jetbrains.kotlin.load.java.components.TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT;
|
||||||
import static org.jetbrains.kotlin.load.java.components.TypeUsage.UPPER_BOUND;
|
import static org.jetbrains.kotlin.load.java.components.TypeUsage.UPPER_BOUND;
|
||||||
@@ -253,7 +250,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
|||||||
TypeParameterDescriptorImpl altParamDescriptor = originalToAltTypeParameters.get(originalTypeParamDescriptor);
|
TypeParameterDescriptorImpl altParamDescriptor = originalToAltTypeParameters.get(originalTypeParamDescriptor);
|
||||||
KtTypeParameter altTypeParameter = altFunDeclaration.getTypeParameters().get(i);
|
KtTypeParameter altTypeParameter = altFunDeclaration.getTypeParameters().get(i);
|
||||||
|
|
||||||
Set<KotlinType> originalUpperBounds = originalTypeParamDescriptor.getUpperBounds();
|
List<KotlinType> originalUpperBounds = originalTypeParamDescriptor.getUpperBounds();
|
||||||
List<KtTypeReference> altUpperBounds = getUpperBounds(altFunDeclaration, altTypeParameter);
|
List<KtTypeReference> altUpperBounds = getUpperBounds(altFunDeclaration, altTypeParameter);
|
||||||
if (altUpperBounds.size() != originalUpperBounds.size()) {
|
if (altUpperBounds.size() != originalUpperBounds.size()) {
|
||||||
if (altUpperBounds.isEmpty()
|
if (altUpperBounds.isEmpty()
|
||||||
|
|||||||
+27
-30
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.lazy.descriptors;
|
package org.jetbrains.kotlin.resolve.lazy.descriptors;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor;
|
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor;
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||||
@@ -28,44 +27,44 @@ import org.jetbrains.kotlin.resolve.lazy.LazyEntity;
|
|||||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescriptor implements LazyEntity {
|
public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescriptor implements LazyEntity {
|
||||||
private final LazyClassContext c;
|
private final LazyClassContext c;
|
||||||
|
private final KtTypeParameter typeParameter;
|
||||||
private final KtTypeParameter jetTypeParameter;
|
|
||||||
|
|
||||||
public LazyTypeParameterDescriptor(
|
public LazyTypeParameterDescriptor(
|
||||||
@NotNull LazyClassContext c,
|
@NotNull LazyClassContext c,
|
||||||
@NotNull LazyClassDescriptor containingDeclaration,
|
@NotNull LazyClassDescriptor containingDeclaration,
|
||||||
@NotNull KtTypeParameter jetTypeParameter,
|
@NotNull KtTypeParameter typeParameter,
|
||||||
int index) {
|
int index
|
||||||
|
) {
|
||||||
super(
|
super(
|
||||||
c.getStorageManager(),
|
c.getStorageManager(),
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
jetTypeParameter.getNameAsSafeName(),
|
typeParameter.getNameAsSafeName(),
|
||||||
jetTypeParameter.getVariance(),
|
typeParameter.getVariance(),
|
||||||
jetTypeParameter.hasModifier(KtTokens.REIFIED_KEYWORD),
|
typeParameter.hasModifier(KtTokens.REIFIED_KEYWORD),
|
||||||
index,
|
index,
|
||||||
KotlinSourceElementKt.toSourceElement(jetTypeParameter)
|
KotlinSourceElementKt.toSourceElement(typeParameter)
|
||||||
);
|
);
|
||||||
this.c = c;
|
this.c = c;
|
||||||
this.jetTypeParameter = jetTypeParameter;
|
this.typeParameter = typeParameter;
|
||||||
|
|
||||||
this.c.getTrace().record(BindingContext.TYPE_PARAMETER, jetTypeParameter, this);
|
this.c.getTrace().record(BindingContext.TYPE_PARAMETER, typeParameter, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Set<KotlinType> resolveUpperBounds() {
|
protected List<KotlinType> resolveUpperBounds() {
|
||||||
Set<KotlinType> upperBounds = Sets.newLinkedHashSet();
|
List<KotlinType> upperBounds = new ArrayList<KotlinType>(1);
|
||||||
|
|
||||||
KtTypeParameter jetTypeParameter = this.jetTypeParameter;
|
KtTypeReference extendsBound = typeParameter.getExtendsBound();
|
||||||
|
|
||||||
KtTypeReference extendsBound = jetTypeParameter.getExtendsBound();
|
|
||||||
if (extendsBound != null) {
|
if (extendsBound != null) {
|
||||||
KotlinType boundType = c.getDescriptorResolver().resolveTypeParameterExtendsBound(
|
KotlinType boundType = c.getDescriptorResolver().resolveTypeParameterExtendsBound(
|
||||||
this, extendsBound, getContainingDeclaration().getScopeForClassHeaderResolution(), c.getTrace());
|
this, extendsBound, getContainingDeclaration().getScopeForClassHeaderResolution(), c.getTrace()
|
||||||
|
);
|
||||||
upperBounds.add(boundType);
|
upperBounds.add(boundType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,32 +77,30 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
|||||||
return upperBounds;
|
return upperBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveUpperBoundsFromWhereClause(Set<KotlinType> upperBounds) {
|
private void resolveUpperBoundsFromWhereClause(@NotNull List<KotlinType> upperBounds) {
|
||||||
KtClassOrObject classOrObject = KtStubbedPsiUtil.getPsiOrStubParent(jetTypeParameter, KtClassOrObject.class, true);
|
KtClassOrObject classOrObject = KtStubbedPsiUtil.getPsiOrStubParent(typeParameter, KtClassOrObject.class, true);
|
||||||
if (classOrObject instanceof KtClass) {
|
if (classOrObject instanceof KtClass) {
|
||||||
KtClass ktClass = (KtClass) classOrObject;
|
for (KtTypeConstraint typeConstraint : classOrObject.getTypeConstraints()) {
|
||||||
for (KtTypeConstraint jetTypeConstraint : ktClass.getTypeConstraints()) {
|
KtSimpleNameExpression constrainedParameterName = typeConstraint.getSubjectTypeParameterName();
|
||||||
KtSimpleNameExpression constrainedParameterName = jetTypeConstraint.getSubjectTypeParameterName();
|
|
||||||
if (constrainedParameterName != null) {
|
if (constrainedParameterName != null) {
|
||||||
if (getName().equals(constrainedParameterName.getReferencedNameAsName())) {
|
if (getName().equals(constrainedParameterName.getReferencedNameAsName())) {
|
||||||
c.getTrace().record(BindingContext.REFERENCE_TARGET, constrainedParameterName, this);
|
c.getTrace().record(BindingContext.REFERENCE_TARGET, constrainedParameterName, this);
|
||||||
|
|
||||||
KtTypeReference boundTypeReference = jetTypeConstraint.getBoundTypeReference();
|
KtTypeReference boundTypeReference = typeConstraint.getBoundTypeReference();
|
||||||
if (boundTypeReference != null) {
|
if (boundTypeReference != null) {
|
||||||
KotlinType boundType = resolveBoundType(boundTypeReference);
|
upperBounds.add(resolveBoundType(boundTypeReference));
|
||||||
upperBounds.add(boundType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private KotlinType resolveBoundType(@NotNull KtTypeReference boundTypeReference) {
|
private KotlinType resolveBoundType(@NotNull KtTypeReference boundTypeReference) {
|
||||||
return c.getTypeResolver()
|
return c.getTypeResolver().resolveType(
|
||||||
.resolveType(getContainingDeclaration().getScopeForClassHeaderResolution(), boundTypeReference,
|
getContainingDeclaration().getScopeForClassHeaderResolution(), boundTypeReference, c.getTrace(), false
|
||||||
c.getTrace(), false);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+5
-2
@@ -34,7 +34,10 @@ import org.jetbrains.kotlin.utils.Interner;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
||||||
|
|
||||||
@@ -414,7 +417,7 @@ public class DescriptorSerializer {
|
|||||||
}
|
}
|
||||||
extension.serializeTypeParameter(typeParameter, builder);
|
extension.serializeTypeParameter(typeParameter, builder);
|
||||||
|
|
||||||
Set<KotlinType> upperBounds = typeParameter.getUpperBounds();
|
List<KotlinType> upperBounds = typeParameter.getUpperBounds();
|
||||||
if (upperBounds.size() == 1 && KotlinBuiltIns.isDefaultBound(CollectionsKt.single(upperBounds))) return builder;
|
if (upperBounds.size() == 1 && KotlinBuiltIns.isDefaultBound(CollectionsKt.single(upperBounds))) return builder;
|
||||||
|
|
||||||
for (KotlinType upperBound : upperBounds) {
|
for (KotlinType upperBound : upperBounds) {
|
||||||
|
|||||||
+14
-20
@@ -16,19 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.lazy.descriptors
|
package org.jetbrains.kotlin.load.java.lazy.descriptors
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
|
||||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
|
||||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver
|
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.toFlexible
|
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
class LazyJavaTypeParameterDescriptor(
|
class LazyJavaTypeParameterDescriptor(
|
||||||
private val c: LazyJavaResolverContext,
|
private val c: LazyJavaResolverContext,
|
||||||
@@ -38,26 +35,23 @@ class LazyJavaTypeParameterDescriptor(
|
|||||||
) : AbstractLazyTypeParameterDescriptor(
|
) : AbstractLazyTypeParameterDescriptor(
|
||||||
c.storageManager,
|
c.storageManager,
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
javaTypeParameter.getName(),
|
javaTypeParameter.name,
|
||||||
Variance.INVARIANT,
|
Variance.INVARIANT,
|
||||||
/* isReified = */ false,
|
/* isReified = */ false,
|
||||||
index,
|
index,
|
||||||
SourceElement.NO_SOURCE
|
SourceElement.NO_SOURCE
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun resolveUpperBounds(): Set<KotlinType> {
|
override fun resolveUpperBounds(): List<KotlinType> {
|
||||||
val bounds = javaTypeParameter.getUpperBounds()
|
val bounds = javaTypeParameter.upperBounds
|
||||||
if (bounds.isEmpty()) {
|
if (bounds.isEmpty()) {
|
||||||
return setOf(LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(
|
return listOf(LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(
|
||||||
c.module.builtIns.getAnyType(),
|
c.module.builtIns.anyType,
|
||||||
c.module.builtIns.getNullableAnyType()
|
c.module.builtIns.nullableAnyType
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
else {
|
return bounds.map {
|
||||||
return bounds.map {
|
c.typeResolver.transformJavaType(it, TypeUsage.UPPER_BOUND.toAttributes(upperBoundForTypeParameter = this))
|
||||||
javaType -> c.typeResolver.transformJavaType(javaType, TypeUsage.UPPER_BOUND.toAttributes(upperBoundForTypeParameter = this))
|
|
||||||
}.toSet()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.types.TypeConstructor;
|
|||||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||||
import org.jetbrains.kotlin.types.Variance;
|
import org.jetbrains.kotlin.types.Variance;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
|
|
||||||
public interface TypeParameterDescriptor extends ClassifierDescriptor {
|
public interface TypeParameterDescriptor extends ClassifierDescriptor {
|
||||||
boolean isReified();
|
boolean isReified();
|
||||||
@@ -31,13 +31,13 @@ public interface TypeParameterDescriptor extends ClassifierDescriptor {
|
|||||||
Variance getVariance();
|
Variance getVariance();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Set<KotlinType> getUpperBounds();
|
List<KotlinType> getUpperBounds();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
KotlinType getUpperBoundsAsType();
|
KotlinType getUpperBoundsAsType();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Set<KotlinType> getLowerBounds();
|
List<KotlinType> getLowerBounds();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+25
-20
@@ -33,18 +33,21 @@ import org.jetbrains.kotlin.types.*;
|
|||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns;
|
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns;
|
||||||
|
|
||||||
public abstract class AbstractTypeParameterDescriptor extends DeclarationDescriptorNonRootImpl implements TypeParameterDescriptor {
|
public abstract class AbstractTypeParameterDescriptor extends DeclarationDescriptorNonRootImpl implements TypeParameterDescriptor {
|
||||||
|
public static final List<KotlinType> FALLBACK_UPPER_BOUNDS_ON_RECURSION =
|
||||||
|
Collections.singletonList(ErrorUtils.createErrorType("Recursion while calculating upper bounds"));
|
||||||
|
|
||||||
private final Variance variance;
|
private final Variance variance;
|
||||||
private final boolean reified;
|
private final boolean reified;
|
||||||
private final int index;
|
private final int index;
|
||||||
|
|
||||||
private final NotNullLazyValue<TypeConstructor> typeConstructor;
|
private final NotNullLazyValue<TypeConstructor> typeConstructor;
|
||||||
private final NotNullLazyValue<KotlinType> defaultType;
|
private final NotNullLazyValue<KotlinType> defaultType;
|
||||||
private final NotNullLazyValue<Set<KotlinType>> upperBounds;
|
private final NotNullLazyValue<List<KotlinType>> upperBounds;
|
||||||
private final NotNullLazyValue<KotlinType> upperBoundsAsType;
|
private final NotNullLazyValue<KotlinType> upperBoundsAsType;
|
||||||
|
|
||||||
protected AbstractTypeParameterDescriptor(
|
protected AbstractTypeParameterDescriptor(
|
||||||
@@ -71,23 +74,26 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
|||||||
this.defaultType = storageManager.createLazyValue(new Function0<KotlinType>() {
|
this.defaultType = storageManager.createLazyValue(new Function0<KotlinType>() {
|
||||||
@Override
|
@Override
|
||||||
public KotlinType invoke() {
|
public KotlinType invoke() {
|
||||||
return KotlinTypeImpl.create(Annotations.Companion.getEMPTY(), getTypeConstructor(), false, Collections.<TypeProjection>emptyList(),
|
return KotlinTypeImpl.create(
|
||||||
new LazyScopeAdapter(storageManager.createLazyValue(
|
Annotations.Companion.getEMPTY(),
|
||||||
new Function0<KtScope>() {
|
getTypeConstructor(), false, Collections.<TypeProjection>emptyList(),
|
||||||
@Override
|
new LazyScopeAdapter(storageManager.createLazyValue(
|
||||||
public KtScope invoke() {
|
new Function0<KtScope>() {
|
||||||
return getUpperBoundsAsType().getMemberScope();
|
@Override
|
||||||
}
|
public KtScope invoke() {
|
||||||
}
|
return getUpperBoundsAsType().getMemberScope();
|
||||||
)));
|
}
|
||||||
|
}
|
||||||
|
))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.upperBounds = storageManager.createRecursionTolerantLazyValue(new Function0<Set<KotlinType>>() {
|
this.upperBounds = storageManager.createRecursionTolerantLazyValue(new Function0<List<KotlinType>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<KotlinType> invoke() {
|
public List<KotlinType> invoke() {
|
||||||
return resolveUpperBounds();
|
return resolveUpperBounds();
|
||||||
}
|
}
|
||||||
}, Collections.singleton(ErrorUtils.createErrorType("Recursion while calculating upper bounds")));
|
}, FALLBACK_UPPER_BOUNDS_ON_RECURSION);
|
||||||
this.upperBoundsAsType = storageManager.createLazyValue(new Function0<KotlinType>() {
|
this.upperBoundsAsType = storageManager.createLazyValue(new Function0<KotlinType>() {
|
||||||
@Override
|
@Override
|
||||||
public KotlinType invoke() {
|
public KotlinType invoke() {
|
||||||
@@ -97,8 +103,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ReadOnly
|
protected abstract List<KotlinType> resolveUpperBounds();
|
||||||
protected abstract Set<KotlinType> resolveUpperBounds();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected abstract TypeConstructor createTypeConstructor();
|
protected abstract TypeConstructor createTypeConstructor();
|
||||||
@@ -121,7 +126,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<KotlinType> getUpperBounds() {
|
public List<KotlinType> getUpperBounds() {
|
||||||
return upperBounds.invoke();
|
return upperBounds.invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +138,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private KotlinType computeUpperBoundsAsType() {
|
private KotlinType computeUpperBoundsAsType() {
|
||||||
Set<KotlinType> upperBounds = getUpperBounds();
|
List<KotlinType> upperBounds = getUpperBounds();
|
||||||
assert !upperBounds.isEmpty() : "Upper bound list is empty in " + getName();
|
assert !upperBounds.isEmpty() : "Upper bound list is empty in " + getName();
|
||||||
KotlinType upperBoundsAsType = TypeIntersector.intersectTypes(KotlinTypeChecker.DEFAULT, upperBounds);
|
KotlinType upperBoundsAsType = TypeIntersector.intersectTypes(KotlinTypeChecker.DEFAULT, upperBounds);
|
||||||
return upperBoundsAsType != null ? upperBoundsAsType : getBuiltIns(this).getNothingType();
|
return upperBoundsAsType != null ? upperBoundsAsType : getBuiltIns(this).getNothingType();
|
||||||
@@ -153,8 +158,8 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<KotlinType> getLowerBounds() {
|
public List<KotlinType> getLowerBounds() {
|
||||||
return Collections.singleton(getBuiltIns(this).getNothingType());
|
return Collections.singletonList(getBuiltIns(this).getNothingType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+4
-4
@@ -28,10 +28,10 @@ import org.jetbrains.kotlin.types.KotlinType;
|
|||||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||||
import org.jetbrains.kotlin.types.TypeConstructorImpl;
|
import org.jetbrains.kotlin.types.TypeConstructorImpl;
|
||||||
import org.jetbrains.kotlin.types.Variance;
|
import org.jetbrains.kotlin.types.Variance;
|
||||||
import org.jetbrains.kotlin.utils.SmartSet;
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns;
|
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns;
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor
|
|||||||
return new TypeParameterDescriptorImpl(containingDeclaration, annotations, reified, variance, name, index, source);
|
return new TypeParameterDescriptorImpl(containingDeclaration, annotations, reified, variance, name, index, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Set<KotlinType> upperBounds = SmartSet.create();
|
private final List<KotlinType> upperBounds = new ArrayList<KotlinType>(1);
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
private TypeParameterDescriptorImpl(
|
private TypeParameterDescriptorImpl(
|
||||||
@@ -132,7 +132,7 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Set<KotlinType> resolveUpperBounds() {
|
protected List<KotlinType> resolveUpperBounds() {
|
||||||
checkInitialized();
|
checkInitialized();
|
||||||
return upperBounds;
|
return upperBounds;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ public class DescriptorSubstitutor {
|
|||||||
index++,
|
index++,
|
||||||
SourceElement.NO_SOURCE
|
SourceElement.NO_SOURCE
|
||||||
);
|
);
|
||||||
substituted.setInitialized();
|
|
||||||
|
|
||||||
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjectionImpl(substituted.getDefaultType()));
|
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjectionImpl(substituted.getDefaultType()));
|
||||||
|
|
||||||
@@ -68,8 +67,11 @@ public class DescriptorSubstitutor {
|
|||||||
for (TypeParameterDescriptor descriptor : typeParameters) {
|
for (TypeParameterDescriptor descriptor : typeParameters) {
|
||||||
TypeParameterDescriptorImpl substituted = substitutedMap.get(descriptor);
|
TypeParameterDescriptorImpl substituted = substitutedMap.get(descriptor);
|
||||||
for (KotlinType upperBound : descriptor.getUpperBounds()) {
|
for (KotlinType upperBound : descriptor.getUpperBounds()) {
|
||||||
substituted.getUpperBounds().add(substitutor.substitute(upperBound, Variance.INVARIANT));
|
KotlinType substitutedBound = substitutor.substitute(upperBound, Variance.INVARIANT);
|
||||||
|
assert substitutedBound != null : "Upper bound failed to substitute: " + descriptor;
|
||||||
|
substituted.addUpperBound(substitutedBound);
|
||||||
}
|
}
|
||||||
|
substituted.setInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
return substitutor;
|
return substitutor;
|
||||||
|
|||||||
@@ -42,11 +42,8 @@ public class TypeIntersector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static KotlinType intersectTypes(
|
public static KotlinType intersectTypes(@NotNull KotlinTypeChecker typeChecker, @NotNull Collection<KotlinType> types) {
|
||||||
@NotNull KotlinTypeChecker typeChecker,
|
assert !types.isEmpty() : "Attempting to intersect empty collection of types, this case should be dealt with on the call site.";
|
||||||
@NotNull Set<KotlinType> types
|
|
||||||
) {
|
|
||||||
assert (!types.isEmpty()) : "Attempting to intersect empty set of types, this case should be dealt with on the call site.";
|
|
||||||
|
|
||||||
if (types.size() == 1) {
|
if (types.size() == 1) {
|
||||||
return types.iterator().next();
|
return types.iterator().next();
|
||||||
@@ -73,7 +70,7 @@ public class TypeIntersector {
|
|||||||
|
|
||||||
if (nullabilityStripped.isEmpty()) {
|
if (nullabilityStripped.isEmpty()) {
|
||||||
// All types were errors
|
// All types were errors
|
||||||
return ErrorUtils.createErrorType("Intersection of errors types: " + types);
|
return ErrorUtils.createErrorType("Intersection of error types: " + types);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we remove types that have subtypes in the list
|
// Now we remove types that have subtypes in the list
|
||||||
@@ -95,7 +92,6 @@ public class TypeIntersector {
|
|||||||
if (!type.equals(other) && typeChecker.isSubtypeOf(other, type)) {
|
if (!type.equals(other) && typeChecker.isSubtypeOf(other, type)) {
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-13
@@ -22,15 +22,19 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
import org.jetbrains.kotlin.serialization.deserialization.Deserialization
|
||||||
|
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
|
||||||
|
import org.jetbrains.kotlin.serialization.deserialization.upperBounds
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class DeserializedTypeParameterDescriptor(
|
class DeserializedTypeParameterDescriptor(
|
||||||
c: DeserializationContext, private val proto: ProtoBuf.TypeParameter, index: Int) : AbstractLazyTypeParameterDescriptor(c.storageManager, c.containingDeclaration, c.nameResolver.getName(proto.name), Deserialization.variance(proto.variance), proto.reified, index, SourceElement.NO_SOURCE) {
|
private val c: DeserializationContext,
|
||||||
private val typeDeserializer: TypeDeserializer = c.typeDeserializer
|
private val proto: ProtoBuf.TypeParameter,
|
||||||
private val typeTable: TypeTable = c.typeTable
|
index: Int
|
||||||
|
) : AbstractLazyTypeParameterDescriptor(
|
||||||
|
c.storageManager, c.containingDeclaration, c.nameResolver.getName(proto.name),
|
||||||
|
Deserialization.variance(proto.variance), proto.reified, index, SourceElement.NO_SOURCE
|
||||||
|
) {
|
||||||
private val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
|
private val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
|
||||||
c.components.annotationAndConstantLoader
|
c.components.annotationAndConstantLoader
|
||||||
.loadTypeParameterAnnotations(proto, c.nameResolver)
|
.loadTypeParameterAnnotations(proto, c.nameResolver)
|
||||||
@@ -39,15 +43,13 @@ class DeserializedTypeParameterDescriptor(
|
|||||||
|
|
||||||
override fun getAnnotations(): Annotations = annotations
|
override fun getAnnotations(): Annotations = annotations
|
||||||
|
|
||||||
override fun resolveUpperBounds(): Set<KotlinType> {
|
override fun resolveUpperBounds(): List<KotlinType> {
|
||||||
val upperBounds = proto.upperBounds(typeTable)
|
val upperBounds = proto.upperBounds(c.typeTable)
|
||||||
if (upperBounds.isEmpty()) {
|
if (upperBounds.isEmpty()) {
|
||||||
return setOf(this.builtIns.getDefaultBound())
|
return listOf(this.builtIns.defaultBound)
|
||||||
}
|
}
|
||||||
val result = LinkedHashSet<KotlinType>(upperBounds.size())
|
return upperBounds.map {
|
||||||
for (upperBound in upperBounds) {
|
c.typeDeserializer.type(it, Annotations.EMPTY)
|
||||||
result.add(typeDeserializer.type(upperBound, Annotations.EMPTY))
|
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user