IR: Avoid "raw" IrTypes

The ir type checker cannot deal with types with an incorrect number of arguments.
On the other hand, the JVM IR backend sometimes produces "raw types" - types with
generic parameters but without arguments. This commit removes such raw types as
much as possible, by replacing calls to "typeWith()" with calls to "defaultType"
for classes without type parametes (defaultType doesn't allocate, unlike typeWith)
and with calls to "starProjectedType" for classes with type parameters.
This commit is contained in:
Steven Schäfer
2019-11-11 11:21:18 +01:00
committed by Alexander Udalov
parent 4d67803f04
commit 2db8471dd7
7 changed files with 44 additions and 37 deletions
@@ -104,6 +104,17 @@ val IrTypeParameter.defaultType: IrType
annotations = emptyList()
)
val IrClassSymbol.starProjectedType: IrSimpleType
get() = IrSimpleTypeImpl(
this,
hasQuestionMark = false,
arguments = owner.typeParameters.map { IrStarProjectionImpl },
annotations = emptyList()
)
fun IrClassifierSymbol.typeWithParameters(parameters: List<IrTypeParameter>): IrSimpleType =
typeWith(parameters.map { it.defaultType })
fun IrClassifierSymbol.typeWith(vararg arguments: IrType): IrSimpleType = typeWith(arguments.toList())
fun IrClassifierSymbol.typeWith(arguments: List<IrType>): IrSimpleType =