Handle type arguments in IrType.eraseTypeParameters

This commit is contained in:
Georgy Bronnikov
2020-01-31 14:44:43 +03:00
parent 22068dd6ad
commit c9df17f2f1
6 changed files with 69 additions and 1 deletions
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.load.java.JavaVisibilities
@@ -51,7 +52,12 @@ fun IrType.eraseTypeParameters() = when (this) {
is IrErrorType -> this
is IrSimpleType ->
when (val owner = classifier.owner) {
is IrClass -> this
is IrClass -> IrSimpleTypeImpl(
classifier,
hasQuestionMark,
arguments.map { it.eraseTypeParameters() },
annotations
)
is IrTypeParameter -> {
val upperBound = owner.erasedUpperBound
IrSimpleTypeImpl(
@@ -66,6 +72,12 @@ fun IrType.eraseTypeParameters() = when (this) {
else -> error("Unknown IrType kind: $this")
}
fun IrTypeArgument.eraseTypeParameters(): IrTypeArgument = when (this) {
is IrStarProjection -> this
is IrTypeProjection -> makeTypeProjection(type.eraseTypeParameters(), variance)
else -> error("Unknown IrTypeArgument kind: $this")
}
/**
* Computes the erased class for this type parameter according to the java erasure rules.
*/