PSI2IR/FIR2IR: do not approximate T!! before translation

This leads to weird effects when it's in a contravariant position,
because it's approximated by Nothing.
This commit is contained in:
pyos
2021-05-10 13:12:02 +02:00
committed by teamcityserver
parent a37db99841
commit d5d6736e67
7 changed files with 35 additions and 22 deletions
@@ -67,6 +67,14 @@ class Fir2IrTypeConverter(
private val typeApproximator = ConeTypeApproximator(session.typeContext, session.languageVersionSettings)
private val typeApproximatorConfiguration =
object : TypeApproximatorConfiguration.AllFlexibleSameValue() {
override val allFlexible: Boolean get() = true
override val errorType: Boolean get() = true
override val integerLiteralType: Boolean get() = true
override val intersectionTypesInContravariantPositions: Boolean get() = true
}
fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType {
capturedTypeCache.clear()
return when (this) {
@@ -232,11 +240,9 @@ class Fir2IrTypeConverter(
} else null
}
}
val typeWithSpecifiedIntersectionTypes = substitutor.substituteOrSelf(type)
return typeApproximator.approximateToSuperType(
typeWithSpecifiedIntersectionTypes,
TypeApproximatorConfiguration.PublicDeclaration
) ?: type
return substitutor.substituteOrSelf(type).let {
typeApproximator.approximateToSuperType(it, typeApproximatorConfiguration) ?: it
}
}
}