FIR: Implement captured type substitution

This commit is contained in:
Simon Ogorodnik
2021-11-15 16:37:34 +03:00
committed by teamcity
parent 476a7727da
commit 61ea65906c
6 changed files with 23 additions and 16 deletions
@@ -61,7 +61,7 @@ abstract class AbstractConeSubstitutor(private val typeContext: ConeTypeContext)
if (it.lowerBound == it.upperBound) it.lowerBound
else it
}
is ConeCapturedType -> return null
is ConeCapturedType -> return substituteCapturedType()
is ConeDefinitelyNotNullType -> this.substituteOriginal()
is ConeIntersectionType -> this.substituteIntersectedTypes()
is ConeStubType -> return null
@@ -69,6 +69,24 @@ abstract class AbstractConeSubstitutor(private val typeContext: ConeTypeContext)
}
}
private fun ConeCapturedType.substituteCapturedType(): ConeCapturedType? {
val innerType = this.lowerType ?: this.constructor.projection.type
val substitutedInnerType = substituteOrNull(innerType) ?: return null
if (substitutedInnerType is ConeCapturedType) return substitutedInnerType
val substitutedSuperTypes =
this.constructor.supertypes?.map { substituteOrSelf(it) }
return ConeCapturedType(
captureStatus,
constructor = ConeCapturedTypeConstructor(
wrapProjection(constructor.projection, substitutedInnerType),
substitutedSuperTypes,
typeParameterMarker = constructor.typeParameterMarker
),
lowerType = if (lowerType != null) substitutedInnerType else null
)
}
private fun ConeIntersectionType.substituteIntersectedTypes(): ConeIntersectionType? {
val substitutedTypes = ArrayList<ConeKotlinType>(intersectedTypes.size)
var somethingIsSubstituted = false