Remove some unjustified usages of TypeParameterDescriptor#getUpperBoundsAsType

This commit is contained in:
Alexander Udalov
2015-10-22 23:14:56 +03:00
parent 426bddb54e
commit bed75e8af2
7 changed files with 39 additions and 22 deletions
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.psi.stubs.KotlinFileStub;
import java.io.IOException;
public class KtFileElementType extends IStubFileElementType<KotlinFileStub> {
public static final int STUB_VERSION = 62;
public static final int STUB_VERSION = 63;
private static final String NAME = "kotlin.FILE";
@@ -14,8 +14,8 @@ public interface I2 : I1 {
public interface Test1 {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun </*0*/ T : kotlin.Cloneable> foo(/*0*/ t: T): kotlin.Unit where T : java.io.Serializable
public abstract fun </*0*/ T : java.io.Serializable> foo(/*0*/ t: T): kotlin.Unit where T : kotlin.Cloneable
public abstract fun </*0*/ T : kotlin.Cloneable> foo(/*0*/ t: T): kotlin.Unit where T : java.io.Serializable
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -9,8 +9,8 @@ public interface A {
public interface B : A {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun </*0*/ T> foo(): kotlin.Unit where T : kotlin.Cloneable
public abstract override /*1*/ /*fake_override*/ fun </*0*/ T : kotlin.Any> foo(): kotlin.Unit where T : kotlin.Cloneable?
public abstract fun </*0*/ T> foo(): kotlin.Unit where T : kotlin.Cloneable
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.SourceElement;
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.ChainedScope;
import org.jetbrains.kotlin.resolve.scopes.KtScope;
import org.jetbrains.kotlin.resolve.scopes.LazyScopeAdapter;
import org.jetbrains.kotlin.storage.NotNullLazyValue;
@@ -32,6 +33,7 @@ import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -54,7 +56,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
@NotNull final StorageManager storageManager,
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull Annotations annotations,
@NotNull Name name,
@NotNull final Name name,
@NotNull Variance variance,
boolean isReified,
int index,
@@ -81,7 +83,15 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
new Function0<KtScope>() {
@Override
public KtScope invoke() {
return getUpperBoundsAsType().getMemberScope();
List<KtScope> scopes = new ArrayList<KtScope>();
for (KotlinType bound : getUpperBounds()) {
scopes.add(bound.getMemberScope());
}
return new ChainedScope(
AbstractTypeParameterDescriptor.this,
"Scope for type parameter " + name.asString(),
scopes.toArray(new KtScope[scopes.size()])
);
}
}
))
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier;
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
import org.jetbrains.kotlin.types.KotlinType;
import java.util.Comparator;
import java.util.List;
@@ -126,11 +127,19 @@ public class MemberComparator implements Comparator<DeclarationDescriptor> {
List<TypeParameterDescriptor> c1TypeParameters = c1.getTypeParameters();
List<TypeParameterDescriptor> c2TypeParameters = c2.getTypeParameters();
for (int i = 0; i < Math.min(c1TypeParameters.size(), c2TypeParameters.size()); i++) {
String p1 = RENDERER.renderType(c1TypeParameters.get(i).getUpperBoundsAsType());
String p2 = RENDERER.renderType(c2TypeParameters.get(i).getUpperBoundsAsType());
int parametersCompareTo = p1.compareTo(p2);
if (parametersCompareTo != 0) {
return parametersCompareTo;
List<KotlinType> c1Bounds = c1TypeParameters.get(i).getUpperBounds();
List<KotlinType> c2Bounds = c2TypeParameters.get(i).getUpperBounds();
int boundsCountCompareTo = c1Bounds.size() - c2Bounds.size();
if (boundsCountCompareTo != 0) {
return boundsCountCompareTo;
}
for (int j = 0; j < c1Bounds.size(); j++) {
String b1 = RENDERER.renderType(c1Bounds.get(j));
String b2 = RENDERER.renderType(c2Bounds.get(j));
int boundCompareTo = b1.compareTo(b2);
if (boundCompareTo != 0) {
return boundCompareTo;
}
}
}
@@ -23,9 +23,7 @@ import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.EQUAL
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.SUB_TYPE
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.Bound
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.BoundKind.EXACT_BOUND
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.BoundKind.LOWER_BOUND
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.BoundKind.UPPER_BOUND
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.BoundKind.*
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.TYPE_BOUND_POSITION
@@ -419,12 +417,12 @@ public class ConstraintSystemImpl : ConstraintSystem {
constraintContext: ConstraintContext
) {
val typeVariable = getMyTypeVariable(parameterType)!!
if (!typeVariable.getUpperBoundsAsType().isDefaultBound()
&& constrainingTypeProjection.getProjectionKind() == Variance.IN_VARIANCE) {
if (!typeVariable.upperBounds.let { it.size == 1 && it.single().isDefaultBound() } &&
constrainingTypeProjection.projectionKind == Variance.IN_VARIANCE) {
errors.add(CannotCapture(constraintContext.position, typeVariable))
}
val typeProjection = if (parameterType.isMarkedNullable()) {
TypeProjectionImpl(constrainingTypeProjection.getProjectionKind(), TypeUtils.makeNotNullable(constrainingTypeProjection.getType()))
val typeProjection = if (parameterType.isMarkedNullable) {
TypeProjectionImpl(constrainingTypeProjection.projectionKind, TypeUtils.makeNotNullable(constrainingTypeProjection.type))
}
else {
constrainingTypeProjection
@@ -229,13 +229,13 @@ public class CommonSupertypes {
nullable |= type.isMarkedNullable();
}
ClassifierDescriptor declarationDescriptor = constructor.getDeclarationDescriptor();
ClassifierDescriptor classifier = constructor.getDeclarationDescriptor();
KtScope newScope;
if (declarationDescriptor instanceof ClassDescriptor) {
newScope = ((ClassDescriptor) declarationDescriptor).getMemberScope(newProjections);
if (classifier instanceof ClassDescriptor) {
newScope = ((ClassDescriptor) classifier).getMemberScope(newProjections);
}
else if (declarationDescriptor instanceof TypeParameterDescriptor) {
newScope = ((TypeParameterDescriptor) declarationDescriptor).getUpperBoundsAsType().getMemberScope();
else if (classifier instanceof TypeParameterDescriptor) {
newScope = classifier.getDefaultType().getMemberScope();
}
else {
newScope = ErrorUtils.createErrorScope("A scope for common supertype which is not a normal classifier", true);