Minor fix of around flexible and not-null FIR types (by semoro)

This commit is contained in:
Mikhail Glukhikh
2019-04-19 10:49:21 +03:00
parent c487c1443f
commit 5bf489327d
3 changed files with 13 additions and 7 deletions
@@ -107,7 +107,7 @@ abstract class ConeTypeParameterType : ConeLookupTagBasedType() {
class ConeFlexibleType(val lowerBound: ConeLookupTagBasedType, val upperBound: ConeLookupTagBasedType) : ConeKotlinType(), class ConeFlexibleType(val lowerBound: ConeKotlinType, val upperBound: ConeKotlinType) : ConeKotlinType(),
FlexibleTypeMarker { FlexibleTypeMarker {
override val typeArguments: Array<out ConeKotlinTypeProjection> override val typeArguments: Array<out ConeKotlinTypeProjection>
get() = emptyArray() get() = emptyArray()
@@ -116,6 +116,9 @@ class ConeFlexibleType(val lowerBound: ConeLookupTagBasedType, val upperBound: C
get() = lowerBound.nullability.takeIf { it == upperBound.nullability } ?: ConeNullability.UNKNOWN get() = lowerBound.nullability.takeIf { it == upperBound.nullability } ?: ConeNullability.UNKNOWN
} }
fun ConeKotlinType.upperBoundIfFlexible() = (this as? ConeFlexibleType)?.upperBound ?: this
fun ConeKotlinType.lowerBoundIfFlexible() = (this as? ConeFlexibleType)?.lowerBound ?: this
class ConeCapturedTypeConstructor(val projection: ConeKotlinTypeProjection, var supertypes: List<ConeKotlinType>? = null) : class ConeCapturedTypeConstructor(val projection: ConeKotlinTypeProjection, var supertypes: List<ConeKotlinType>? = null) :
TypeConstructorMarker { TypeConstructorMarker {
@@ -57,7 +57,7 @@ abstract class AbstractConeSubstitutor : ConeSubstitutor {
override fun substituteOrNull(type: ConeKotlinType): ConeKotlinType? { override fun substituteOrNull(type: ConeKotlinType): ConeKotlinType? {
val newType = substituteType(type) val newType = substituteType(type)
return (newType ?: type).substituteRecursive() ?: newType return (newType ?: type.substituteRecursive()) ?: newType
} }
private fun ConeKotlinType.substituteRecursive(): ConeKotlinType? { private fun ConeKotlinType.substituteRecursive(): ConeKotlinType? {
@@ -78,10 +78,13 @@ abstract class AbstractConeSubstitutor : ConeSubstitutor {
} }
private fun ConeFlexibleType.substituteBounds(): ConeFlexibleType? { private fun ConeFlexibleType.substituteBounds(): ConeFlexibleType? {
val newLowerBound = substituteOrNull(lowerBound) as ConeLookupTagBasedType? val newLowerBound = substituteOrNull(lowerBound)
val newUpperBound = substituteOrNull(upperBound) as ConeLookupTagBasedType? val newUpperBound = substituteOrNull(upperBound)
if (newLowerBound != null || newUpperBound != null) { if (newLowerBound != null || newUpperBound != null) {
return ConeFlexibleType(newLowerBound ?: lowerBound, newUpperBound ?: upperBound) return ConeFlexibleType(
newLowerBound?.lowerBoundIfFlexible() ?: lowerBound,
newUpperBound?.upperBoundIfFlexible() ?: upperBound
)
} }
return null return null
} }
@@ -86,12 +86,12 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext {
override fun FlexibleTypeMarker.upperBound(): SimpleTypeMarker { override fun FlexibleTypeMarker.upperBound(): SimpleTypeMarker {
require(this is ConeFlexibleType) require(this is ConeFlexibleType)
return this.upperBound return this.upperBound as SimpleTypeMarker
} }
override fun FlexibleTypeMarker.lowerBound(): SimpleTypeMarker { override fun FlexibleTypeMarker.lowerBound(): SimpleTypeMarker {
require(this is ConeFlexibleType) require(this is ConeFlexibleType)
return this.lowerBound return this.lowerBound as SimpleTypeMarker
} }
override fun SimpleTypeMarker.asCapturedType(): CapturedTypeMarker? { override fun SimpleTypeMarker.asCapturedType(): CapturedTypeMarker? {