Minor. Fix potential deadlock

This commit is contained in:
Stanislav Erokhin
2015-10-30 19:40:45 +03:00
parent 77411b2181
commit 25a168d2a4
@@ -129,6 +129,26 @@ public open class DelegatingFlexibleType protected constructor(
}
}
// These assertions are needed for checking invariants of flexible types.
//
// Unfortunately isSubtypeOf is running resolve for lazy types.
// Because of this we can't run these assertions when we are creating this type. See EA-74904
//
// Also isSubtypeOf is not a very fast operation, so we are running assertions only if ASSERTIONS_ENABLED. See KT-7540
private var assertionsDone = false
private fun runAssertions() {
if (assertionsDone || !ASSERTIONS_ENABLED) return
assertionsDone = true
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 <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
val extra = extraCapabilities.getCapability(capabilityClass, this, this)
if (extra != null) return extra
@@ -150,17 +170,10 @@ public open class DelegatingFlexibleType protected constructor(
override fun isMarkedNullable(): Boolean = getCapability(javaClass<NullAwareness>())!!.computeIsNullable()
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 val delegateType: KotlinType
get() {
runAssertions()
return lowerBound
}
override fun getDelegate() = getCapability(javaClass<FlexibleTypeDelegation>())!!.delegateType