diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractTypeConstructor.kt index c6b64deb0a4..62e37b49c00 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractTypeConstructor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractTypeConstructor.kt @@ -28,12 +28,12 @@ abstract class AbstractTypeConstructor(storageManager: StorageManager) : TypeCon private class Supertypes( val allSupertypes: Collection) { // initializer is only needed as a stub for case when 'getSupertypes' is called while 'supertypes' are being calculated - var supertypesWithoutCycles: List = listOf(ERROR_TYPE) + var supertypesWithoutCycles: List = listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES) } private val supertypes = storageManager.createLazyValueWithPostCompute( { Supertypes(computeSupertypes()) }, - { Supertypes(listOf(ERROR_TYPE)) }, + { Supertypes(listOf(ErrorUtils.ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES)) }, { supertypes -> // It's important that loops disconnection begins in post-compute phase, because it guarantees that // when we start calculation supertypes of supertypes (for computing neighbours), they start their disconnection loop process @@ -51,20 +51,17 @@ abstract class AbstractTypeConstructor(storageManager: StorageManager) : TypeCon supertypes.supertypesWithoutCycles = (resultWithoutCycles as? List) ?: resultWithoutCycles.toList() }) + private fun TypeConstructor.computeNeighbours(): Collection = + (this as? AbstractTypeConstructor)?.let { + abstractClassifierDescriptor -> + abstractClassifierDescriptor.supertypes().allSupertypes + + abstractClassifierDescriptor.getAdditionalNeighboursInSupertypeGraph() + } ?: supertypes + protected abstract fun computeSupertypes(): Collection protected abstract val supertypeLoopChecker: SupertypeLoopChecker protected open fun reportSupertypeLoopError(type: KotlinType) {} protected open fun getAdditionalNeighboursInSupertypeGraph(): Collection = emptyList() protected open fun defaultSupertypeIfEmpty(): KotlinType? = null - private companion object { - val ERROR_TYPE = ErrorUtils.createErrorType("Loop in supertypes") - - fun TypeConstructor.computeNeighbours(): Collection = - (this as? AbstractTypeConstructor)?.let { - abstractClassifierDescriptor -> - abstractClassifierDescriptor.supertypes().allSupertypes + - abstractClassifierDescriptor.getAdditionalNeighboursInSupertypeGraph() - } ?: supertypes - } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index cb8a36db968..d6cdcf82495 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -330,6 +330,9 @@ public class ErrorUtils { return new ErrorScope(debugMessage); } + // Do not move it into AbstractTypeConstructor.Companion because of cycle in initialization(see KT-13264) + public static final SimpleType ERROR_TYPE_FOR_LOOP_IN_SUPERTYPES = createErrorType(""); + private static final KotlinType ERROR_PROPERTY_TYPE = createErrorType(""); private static final PropertyDescriptor ERROR_PROPERTY = createErrorProperty();