From 0120139f9c1ecc01a11569b403f9e8206fcc429a Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Wed, 28 Oct 2015 13:08:28 +0300 Subject: [PATCH] Fix for EA-74904. --- .../jetbrains/kotlin/types/flexibleTypes.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt index 5edb6f69227..cfa307ac139 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt @@ -129,17 +129,6 @@ public open class DelegatingFlexibleType protected constructor( } } - init { - if (ASSERTIONS_ENABLED) { // workaround for KT-7540 - assert (!lowerBound.isFlexible()) { "Lower bound of a flexible type can not be flexible: $lowerBound" } - assert (!upperBound.isFlexible()) { "Upper bound of a flexible type can not be flexible: $upperBound" } - assert (lowerBound != upperBound) { "Lower and upper bounds are equal: $lowerBound == $upperBound" } - assert (KotlinTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) { - "Lower bound $lowerBound of a flexible type must be a subtype of the upper bound $upperBound" - } - } - } - override fun getCapability(capabilityClass: Class): T? { val extra = extraCapabilities.getCapability(capabilityClass, this, this) if (extra != null) return extra @@ -161,7 +150,18 @@ public open class DelegatingFlexibleType protected constructor( override fun isMarkedNullable(): Boolean = getCapability(javaClass())!!.computeIsNullable() - override val delegateType: KotlinType = lowerBound + override val delegateType: KotlinType by lazy { + // we can't check this in init block, because lowerBound & upperBound can be LazyType. see EA-74904 + if (ASSERTIONS_ENABLED) { // workaround for KT-7540 + assert (!lowerBound.isFlexible()) { "Lower bound of a flexible type can not be flexible: $lowerBound" } + assert (!upperBound.isFlexible()) { "Upper bound of a flexible type can not be flexible: $upperBound" } + assert (lowerBound != upperBound) { "Lower and upper bounds are equal: $lowerBound == $upperBound" } + assert (KotlinTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) { + "Lower bound $lowerBound of a flexible type must be a subtype of the upper bound $upperBound" + } + } + lowerBound + } override fun getDelegate() = getCapability(javaClass())!!.delegateType