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
@@ -18,13 +18,13 @@ package org.jetbrains.kotlin.load.java
import org.jetbrains.kotlin.name.FqName
val JSPECIFY_NULLABLE = FqName("jspecify.annotations.Nullable")
val JSPECIFY_NOT_NULL = FqName("jspecify.annotations.NotNull")
val JSPECIFY_NULLNESS_UNKNOWN = FqName("jspecify.annotations.NullnessUnknown")
val JSPECIFY_NULLABLE = FqName("org.jspecify.annotations.Nullable")
val JSPECIFY_NOT_NULL = FqName("org.jspecify.annotations.NotNull")
val JSPECIFY_NULLNESS_UNKNOWN = FqName("org.jspecify.annotations.NullnessUnknown")
val JSPECIFY_DEFAULT_NULLABLE = FqName("jspecify.annotations.DefaultNullable")
val JSPECIFY_DEFAULT_NOT_NULL = FqName("jspecify.annotations.DefaultNotNull")
val JSPECIFY_DEFAULT_NULLNESS_UNKNOWN = FqName("jspecify.annotations.DefaultNullnessUnknown")
val JSPECIFY_DEFAULT_NULLABLE = FqName("org.jspecify.annotations.DefaultNullable")
val JSPECIFY_DEFAULT_NOT_NULL = FqName("org.jspecify.annotations.DefaultNotNull")
val JSPECIFY_DEFAULT_NULLNESS_UNKNOWN = FqName("org.jspecify.annotations.DefaultNullnessUnknown")
val NULLABLE_ANNOTATIONS = listOf(
JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION,
@@ -45,7 +45,7 @@ class LazyJavaTypeParameterDescriptor(
override val annotations = LazyJavaAnnotations(c, javaTypeParameter)
override fun resolveUpperBounds(): List<KotlinType> {
return computeNotEnhancedBounds().let { c.components.signatureEnhancement.enhanceTypeParameterBounds(this, it, c) }
return computeNotEnhancedBounds()
}
private fun computeNotEnhancedBounds(): List<KotlinType> {
@@ -63,6 +63,10 @@ class LazyJavaTypeParameterDescriptor(
}
}
override fun processBoundsWithoutCycles(bounds: List<KotlinType>): List<KotlinType> {
return c.components.signatureEnhancement.enhanceTypeParameterBounds(this, bounds, c)
}
override fun reportSupertypeLoopError(type: KotlinType) {
// Do nothing
}
@@ -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