Minor. Fix potential deadlock
This commit is contained in:
@@ -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? {
|
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||||
val extra = extraCapabilities.getCapability(capabilityClass, this, this)
|
val extra = extraCapabilities.getCapability(capabilityClass, this, this)
|
||||||
if (extra != null) return extra
|
if (extra != null) return extra
|
||||||
@@ -150,17 +170,10 @@ public open class DelegatingFlexibleType protected constructor(
|
|||||||
|
|
||||||
override fun isMarkedNullable(): Boolean = getCapability(javaClass<NullAwareness>())!!.computeIsNullable()
|
override fun isMarkedNullable(): Boolean = getCapability(javaClass<NullAwareness>())!!.computeIsNullable()
|
||||||
|
|
||||||
override val delegateType: KotlinType by lazy {
|
override val delegateType: KotlinType
|
||||||
// we can't check this in init block, because lowerBound & upperBound can be LazyType. see EA-74904
|
get() {
|
||||||
if (ASSERTIONS_ENABLED) { // workaround for KT-7540
|
runAssertions()
|
||||||
assert (!lowerBound.isFlexible()) { "Lower bound of a flexible type can not be flexible: $lowerBound" }
|
return 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<FlexibleTypeDelegation>())!!.delegateType
|
override fun getDelegate() = getCapability(javaClass<FlexibleTypeDelegation>())!!.delegateType
|
||||||
|
|||||||
Reference in New Issue
Block a user