[IR] Make IrTypeArgument a sealed interface

This commit is contained in:
Sergej Jaskiewicz
2023-01-19 19:35:41 +01:00
committed by Space Team
parent c65b689fa0
commit 1f76d39e66
25 changed files with 59 additions and 73 deletions
@@ -101,7 +101,7 @@ internal class AddFunctionSupertypeToSuspendFunctionLowering(val context: Contex
require(type.classOrNull == continuationClassSymbol)
when (val typeArgument = (type as IrSimpleType).arguments.single()) {
is IrTypeProjection -> typeArgument.type
else -> context.irBuiltIns.anyNType
is IrStarProjection -> context.irBuiltIns.anyNType
}
} else {
type
@@ -116,4 +116,4 @@ internal class AddFunctionSupertypeToSuspendFunctionLowering(val context: Contex
})
}
}
}
@@ -154,7 +154,6 @@ internal class KTypeGenerator(
when (argument) {
is IrStarProjection -> irConstantInt(-1)
is IrTypeProjection -> irConstantInt(mapVariance(argument.variance))
else -> error("Unexpected IrTypeArgument: $argument (${argument::class})")
}
})
val type = irConstantArray(
@@ -163,7 +162,6 @@ internal class KTypeGenerator(
when (argument) {
is IrStarProjection -> irConstantPrimitive(irNull())
is IrTypeProjection -> irKType(argument.type, leaveReifiedForLater, seenTypeParameters)
else -> error("Unexpected IrTypeArgument: $argument (${argument::class})")
}
})
return irConstantObject(
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrTypeOperator
import org.jetbrains.kotlin.ir.expressions.IrTypeOperatorCall
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrStarProjection
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.IrTypeProjection
import org.jetbrains.kotlin.ir.types.impl.buildSimpleType
@@ -37,20 +38,21 @@ internal class SamSuperTypesChecker(private val context: Context,
this.nullability = this@eraseProjections.nullability
this.annotations = this@eraseProjections.annotations
this.arguments = this@eraseProjections.arguments.mapIndexed { index, argument ->
if (argument !is IrTypeProjection)
argument
else {
if (mode == Mode.THROW && argument.variance != Variance.INVARIANT) {
context.reportCompilationError(
"Unexpected variance in super type argument: ${argument.variance} @$index", irFile, owner)
when (argument) {
is IrStarProjection -> argument
is IrTypeProjection -> {
if (mode == Mode.THROW && argument.variance != Variance.INVARIANT) {
context.reportCompilationError(
"Unexpected variance in super type argument: ${argument.variance} @$index", irFile, owner)
}
val newArgumentType = if (recurse) {
argument.type.eraseProjections(owner)
} else {
// See the explanation at the SamSuperTypesChecker constructor call sites.
argument.type
}
makeTypeProjection(newArgumentType, Variance.INVARIANT)
}
val newArgumentType = if (recurse) {
argument.type.eraseProjections(owner)
} else {
// See the explanation at the SamSuperTypesChecker constructor call sites.
argument.type
}
makeTypeProjection(newArgumentType, Variance.INVARIANT)
}
}
}
@@ -67,4 +69,4 @@ internal class SamSuperTypesChecker(private val context: Context,
}
})
}
}
}
@@ -183,7 +183,6 @@ fun IrType.substitute(map: Map<IrTypeParameterSymbol, IrType>): IrType {
when (it) {
is IrTypeProjection -> makeTypeProjection(it.type.substitute(map), it.variance)
is IrStarProjection -> it
else -> error(it)
}
}
IrSimpleTypeImpl(classifier, nullability, newArguments, annotations)