Disconnect loops between upper bounds of type parameters
#KT-9759 Fixed
This commit is contained in:
+1
-1
@@ -416,7 +416,7 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(TYPE_MISMATCH_IN_RANGE, "Type mismatch: incompatible types of range and element checked in it");
|
||||
MAP.put(CYCLIC_INHERITANCE_HIERARCHY, "There's a cycle in the inheritance hierarchy for this type");
|
||||
MAP.put(CYCLIC_GENERIC_UPPER_BOUND, "Type parameter has itself as an upper bound");
|
||||
MAP.put(CYCLIC_GENERIC_UPPER_BOUND, "Type parameter has cyclic upper bounds");
|
||||
|
||||
MAP.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list");
|
||||
MAP.put(SUPERTYPE_NOT_A_CLASS_OR_INTERFACE, "Only classes and interfaces may serve as supertypes");
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiElement;
|
||||
import kotlin.CollectionsKt;
|
||||
import kotlin.SetsKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -410,9 +411,9 @@ public class DescriptorResolver {
|
||||
DeclarationDescriptor containingDescriptor,
|
||||
LexicalWritableScope extensibleScope,
|
||||
LexicalScope scopeForAnnotationsResolve,
|
||||
KtTypeParameter typeParameter,
|
||||
final KtTypeParameter typeParameter,
|
||||
int index,
|
||||
BindingTrace trace
|
||||
final BindingTrace trace
|
||||
) {
|
||||
if (typeParameter.getVariance() != Variance.INVARIANT) {
|
||||
assert !(containingDescriptor instanceof ClassifierDescriptor) : "This method is intended for functions/properties";
|
||||
@@ -429,8 +430,16 @@ public class DescriptorResolver {
|
||||
typeParameter.getVariance(),
|
||||
KtPsiUtil.safeName(typeParameter.getName()),
|
||||
index,
|
||||
KotlinSourceElementKt.toSourceElement(typeParameter)
|
||||
);
|
||||
KotlinSourceElementKt.toSourceElement(typeParameter),
|
||||
new Function1<KotlinType, Void>() {
|
||||
@Override
|
||||
public Void invoke(KotlinType type) {
|
||||
trace.report(Errors.CYCLIC_GENERIC_UPPER_BOUND.on(typeParameter));
|
||||
return null;
|
||||
}
|
||||
},
|
||||
supertypeLoopsResolver
|
||||
);
|
||||
trace.record(BindingContext.TYPE_PARAMETER, typeParameter, typeParameterDescriptor);
|
||||
extensibleScope.addClassifierDescriptor(typeParameterDescriptor);
|
||||
return typeParameterDescriptor;
|
||||
@@ -461,20 +470,6 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
public KotlinType resolveTypeParameterExtendsBound(
|
||||
@NotNull TypeParameterDescriptor typeParameterDescriptor,
|
||||
@NotNull KtTypeReference extendsBound,
|
||||
LexicalScope scope,
|
||||
BindingTrace trace
|
||||
) {
|
||||
KotlinType type = typeResolver.resolveType(scope, extendsBound, trace, false);
|
||||
if (type.getConstructor().equals(typeParameterDescriptor.getTypeConstructor())) {
|
||||
trace.report(Errors.CYCLIC_GENERIC_UPPER_BOUND.on(extendsBound));
|
||||
type = ErrorUtils.createErrorType("Cyclic upper bound: " + type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public void resolveGenericBounds(
|
||||
@NotNull KtTypeParameterListOwner declaration,
|
||||
@NotNull DeclarationDescriptor descriptor,
|
||||
@@ -494,7 +489,7 @@ public class DescriptorResolver {
|
||||
|
||||
KtTypeReference extendsBound = jetTypeParameter.getExtendsBound();
|
||||
if (extendsBound != null) {
|
||||
KotlinType type = resolveTypeParameterExtendsBound(typeParameterDescriptor, extendsBound, scope, trace);
|
||||
KotlinType type = typeResolver.resolveType(scope, extendsBound, trace, false);
|
||||
typeParameterDescriptor.addUpperBound(type);
|
||||
deferredUpperBoundCheckerTasks.add(new UpperBoundCheckerTask(extendsBound, type));
|
||||
}
|
||||
@@ -523,9 +518,10 @@ public class DescriptorResolver {
|
||||
|
||||
for (TypeParameterDescriptorImpl parameter : parameters) {
|
||||
parameter.addDefaultUpperBound();
|
||||
|
||||
parameter.setInitialized();
|
||||
}
|
||||
|
||||
for (TypeParameterDescriptorImpl parameter : parameters) {
|
||||
checkConflictingUpperBounds(trace, parameter, typeParameters.get(parameter.getIndex()));
|
||||
}
|
||||
|
||||
|
||||
+18
@@ -18,7 +18,9 @@ package org.jetbrains.kotlin.resolve.lazy.descriptors;
|
||||
|
||||
import kotlin.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker;
|
||||
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
@@ -58,6 +60,22 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
this.c.getTrace().record(BindingContext.TYPE_PARAMETER, typeParameter, this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected SupertypeLoopChecker getSupertypeLoopChecker() {
|
||||
return c.getSupertypeLoopChecker();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reportCycleError(@NotNull KotlinType type) {
|
||||
for (KtTypeReference typeReference : getAllUpperBounds()) {
|
||||
if (resolveBoundType(typeReference).getConstructor().equals(type.getConstructor())) {
|
||||
c.getTrace().report(Errors.CYCLIC_GENERIC_UPPER_BOUND.on(typeReference));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<KotlinType> resolveUpperBounds() {
|
||||
|
||||
Reference in New Issue
Block a user