[FIR2IR] Pass type context for type argument conversion properly

This commit is contained in:
Mikhail Glukhikh
2020-08-31 14:04:11 +03:00
parent 04af6846a7
commit 1e360d9c91
6 changed files with 45 additions and 30 deletions
@@ -471,7 +471,10 @@ class Fir2IrClassifierStorage(
firTypeParameterSymbol: FirTypeParameterSymbol,
typeContext: ConversionTypeContext
): IrTypeParameterSymbol {
return getCachedIrTypeParameter(firTypeParameterSymbol.fir, typeContext = typeContext)?.symbol
val firTypeParameter = firTypeParameterSymbol.fir
return getCachedIrTypeParameter(firTypeParameter, typeContext = typeContext)?.symbol
// We can try to use default cache because setter can use parent type parameters
?: typeParameterCache[firTypeParameter]?.symbol
?: error("Cannot find cached type parameter by FIR symbol: ${firTypeParameterSymbol.name}")
}
}
@@ -92,7 +92,7 @@ class Fir2IrTypeConverter(
typeAnnotations += with(annotationGenerator) { annotations.toIrAnnotations() }
IrSimpleTypeImpl(
irSymbol, !typeContext.definitelyNotNull && this.isMarkedNullable,
fullyExpandedType(session).typeArguments.map { it.toIrTypeArgument() },
fullyExpandedType(session).typeArguments.map { it.toIrTypeArgument(typeContext) },
typeAnnotations
)
}
@@ -115,19 +115,19 @@ class Fir2IrTypeConverter(
}
}
private fun ConeTypeProjection.toIrTypeArgument(): IrTypeArgument {
private fun ConeTypeProjection.toIrTypeArgument(typeContext: ConversionTypeContext): IrTypeArgument {
return when (this) {
ConeStarProjection -> IrStarProjectionImpl
is ConeKotlinTypeProjectionIn -> {
val irType = this.type.toIrType()
val irType = this.type.toIrType(typeContext)
makeTypeProjection(irType, Variance.IN_VARIANCE)
}
is ConeKotlinTypeProjectionOut -> {
val irType = this.type.toIrType()
val irType = this.type.toIrType(typeContext)
makeTypeProjection(irType, Variance.OUT_VARIANCE)
}
is ConeKotlinType -> {
val irType = toIrType()
val irType = toIrType(typeContext)
makeTypeProjection(irType, Variance.INVARIANT)
}
}