Enhance bounds for type parameters after loops disconnection

Otherwise behavior might change because enhancement may force computation
for other type parameters in cases like:
class A<X extends Y, Y extends X> {}

See the test:
org.jetbrains.kotlin.checkers.DiagnosticsTestGenerated.Tests.J_k#testRecursiveRawUpperBound3
This commit is contained in:
Denis Zharkov
2019-08-22 18:20:22 +03:00
committed by Victor Petukhov
parent 6661814e40
commit 59bd7364ab
51 changed files with 363 additions and 115 deletions
@@ -136,6 +136,11 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
return (TypeParameterDescriptor) super.getOriginal();
}
@NotNull
protected List<KotlinType> processBoundsWithoutCycles(@NotNull List<KotlinType> bounds) {
return bounds;
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitTypeParameterDescriptor(this, data);
@@ -206,6 +211,12 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
AbstractTypeParameterDescriptor.this.reportSupertypeLoopError(type);
}
@NotNull
@Override
protected List<KotlinType> processSupertypesWithoutCycles(@NotNull List<KotlinType> supertypes) {
return processBoundsWithoutCycles(supertypes);
}
@Nullable
@Override
protected KotlinType defaultSupertypeIfEmpty() {
@@ -17,7 +17,9 @@
package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.checker.refineTypes
@@ -105,7 +107,8 @@ abstract class AbstractTypeConstructor(storageManager: StorageManager) : TypeCon
)
}
supertypes.supertypesWithoutCycles = (resultWithoutCycles as? List<KotlinType>) ?: resultWithoutCycles.toList()
supertypes.supertypesWithoutCycles =
processSupertypesWithoutCycles(resultWithoutCycles as? List<KotlinType> ?: resultWithoutCycles.toList())
})
private fun TypeConstructor.computeNeighbours(useCompanions: Boolean): Collection<KotlinType> =
@@ -118,6 +121,8 @@ abstract class AbstractTypeConstructor(storageManager: StorageManager) : TypeCon
protected abstract val supertypeLoopChecker: SupertypeLoopChecker
protected open fun reportSupertypeLoopError(type: KotlinType) {}
protected open fun processSupertypesWithoutCycles(supertypes: List<@JvmSuppressWildcards KotlinType>): List<KotlinType> = supertypes
// TODO: overload in AbstractTypeParameterDescriptor?
protected open fun reportScopesLoopError(type: KotlinType) {}
protected open val shouldReportCyclicScopeWithCompanionWarning: Boolean = false