From 1f76d39e66b4ee8544feac93e4afd8e61ef9610a Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Thu, 19 Jan 2023 19:35:41 +0100 Subject: [PATCH] [IR] Make IrTypeArgument a sealed interface --- .../js/export/TransitiveExportCollector.kt | 1 - .../kotlin/ir/backend/js/utils/IrTypeUtils.kt | 1 - .../jvm/lower/FunctionReferenceLowering.kt | 2 +- .../jvm/lower/MainMethodGenerationLowering.kt | 2 +- .../backend/jvm/lower/ToArrayLowering.kt | 1 - .../kotlin/backend/jvm/ir/JvmIrTypeUtils.kt | 2 -- .../state/reflection/KTypeState.kt | 3 +- .../ir/descriptors/IrBasedDescriptors.kt | 1 - .../org/jetbrains/kotlin/ir/types/IrType.kt | 5 +++- .../kotlin/ir/types/IrTypeSubstitutor.kt | 30 +++++++++---------- .../jetbrains/kotlin/ir/types/IrTypeUtils.kt | 4 +-- .../org/jetbrains/kotlin/ir/types/irTypes.kt | 1 - .../kotlin/ir/util/DeepCopyTypeRemapper.kt | 10 +++---- .../kotlin/ir/util/IrTypeParameterRemapper.kt | 8 ++--- .../jetbrains/kotlin/ir/util/IrTypeUtils.kt | 7 ++--- .../org/jetbrains/kotlin/ir/util/IrUtils.kt | 2 +- .../kotlin/ir/util/RenderIrElement.kt | 3 -- .../kotlin/ir/util/SimpleTypeRemapper.kt | 8 ++--- .../common/serialization/IrFileSerializer.kt | 2 -- ...ctionSupertypeToSuspendFunctionLowering.kt | 4 +-- .../backend/konan/lower/ReflectionSupport.kt | 2 -- .../konan/lower/SamSuperTypesChecker.kt | 30 ++++++++++--------- .../org/jetbrains/kotlin/ir/util/IrUtils2.kt | 1 - .../kotlin/android/parcel/ir/irUtils.kt | 1 - .../jetbrains/kotlin/parcelize/ir/irUtils.kt | 1 - 25 files changed, 59 insertions(+), 73 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/TransitiveExportCollector.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/TransitiveExportCollector.kt index 248c4eacfac..be353318b5d 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/TransitiveExportCollector.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/TransitiveExportCollector.kt @@ -66,7 +66,6 @@ class TransitiveExportCollector(val context: JsIrBackendContext) { is IrType -> substitute(typeSubstitutionMap) is IrTypeProjection -> type.substitute(typeSubstitutionMap) is IrStarProjection -> context.irBuiltIns.anyNType - else -> error("Unexpected ir type argument") } } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/IrTypeUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/IrTypeUtils.kt index ad01853aba6..344ee46fc67 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/IrTypeUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/IrTypeUtils.kt @@ -39,7 +39,6 @@ fun IrType.asString(): String = when (this) { private fun IrTypeArgument.asString(): String = when (this) { is IrStarProjection -> "*" is IrTypeProjection -> variance.label + (if (variance != Variance.INVARIANT) " " else "") + type.asString() - else -> error("Unexpected kind of IrTypeArgument: " + javaClass.simpleName) } private fun IrClassifierSymbol.asString() = when (this) { diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt index aeea6016a57..8d75302ae6c 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt @@ -442,7 +442,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext) private val parameterTypes = (irFunctionReference.type as IrSimpleType).arguments.map { when (it) { is IrTypeProjection -> it.type - else -> context.irBuiltIns.anyNType + is IrStarProjection -> context.irBuiltIns.anyNType } } private val argumentTypes = parameterTypes.dropLast(1) diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/MainMethodGenerationLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/MainMethodGenerationLowering.kt index 97dafce1232..ea51c9b941f 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/MainMethodGenerationLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/MainMethodGenerationLowering.kt @@ -111,7 +111,7 @@ private class MainMethodGenerationLowering(private val context: JvmBackendContex is IrTypeProjection -> { (argType.variance != Variance.IN_VARIANCE) && argType.type.isStringClassType() } - else -> false + is IrStarProjection -> false } } diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/ToArrayLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/ToArrayLowering.kt index a03eed06303..873dfc3cb47 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/ToArrayLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/ToArrayLowering.kt @@ -150,7 +150,6 @@ private fun IrType.isArrayOrNullableArrayOf(context: JvmBackendContext, element: this is IrSimpleType && (isArray() || isNullableArray()) && arguments.size == 1 && element == when (val it = arguments[0]) { is IrStarProjection -> context.irBuiltIns.anyClass is IrTypeProjection -> if (it.variance == Variance.IN_VARIANCE) context.irBuiltIns.anyClass else it.type.classifierOrNull - else -> null } // Match `fun toArray(prototype: Array): Array` diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt index 95939769d5a..c5dfebf4f1a 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrTypeUtils.kt @@ -62,7 +62,6 @@ fun IrType.eraseTypeParameters(): IrType = when (this) { private fun IrTypeArgument.eraseTypeParameters(): IrTypeArgument = when (this) { is IrStarProjection -> this is IrTypeProjection -> makeTypeProjection(type.eraseTypeParameters(), variance) - else -> error("Unknown IrTypeArgument kind: $this") } /** @@ -147,7 +146,6 @@ fun IrType.eraseToScope(visibleTypeParameters: Set): IrType { private fun IrTypeArgument.eraseToScope(visibleTypeParameters: Set): IrTypeArgument = when (this) { is IrStarProjection -> this is IrTypeProjection -> makeTypeProjection(type.eraseToScope(visibleTypeParameters), variance) - else -> error("unknown type projection kind: ${render()}") } fun collectVisibleTypeParameters(scopeOwner: IrTypeParametersContainer): Set = diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/state/reflection/KTypeState.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/state/reflection/KTypeState.kt index 88ffe706957..020b553c356 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/state/reflection/KTypeState.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/state/reflection/KTypeState.kt @@ -53,7 +53,6 @@ internal class KTypeState(val irType: IrType, override val irClass: IrClass) : R is IrSimpleType -> Variance.INVARIANT is IrTypeProjection -> this.variance is IrStarProjection -> null - else -> TODO() } } @@ -75,4 +74,4 @@ internal class KTypeState(val irType: IrType, override val irClass: IrClass) : R override fun toString(): String { return irType.renderType() } -} \ No newline at end of file +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt index 02837768a2a..def9920b8eb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt @@ -1174,7 +1174,6 @@ private fun makeKotlinType( when (it) { is IrTypeProjection -> TypeProjectionImpl(it.variance, it.type.toIrBasedKotlinType()) is IrStarProjection -> StarProjectionImpl(classDescriptor.typeConstructor.parameters[index]) - else -> error(it) } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt index 8088a0f10dc..89e1443f508 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt @@ -92,7 +92,10 @@ abstract class IrSimpleType(kotlinType: KotlinType?) : IrTypeBase(kotlinType), S get() = nullability == SimpleTypeNullability.MARKED_NULLABLE } -interface IrTypeArgument : TypeArgumentMarker { +/** + * An argument for a generic parameter. Can be either [IrTypeProjection], or [IrStarProjection]. + */ +sealed interface IrTypeArgument : TypeArgumentMarker { override fun equals(other: Any?): Boolean override fun hashCode(): Int } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSubstitutor.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSubstitutor.kt index c97b7913c16..0980e228cc8 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSubstitutor.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSubstitutor.kt @@ -31,7 +31,6 @@ abstract class AbstractIrTypeSubstitutor(private val irBuiltIns: IrBuiltIns) : T when (val typeArgument = getSubstitutionArgument(it)) { is IrStarProjection -> irBuiltIns.anyNType // TODO upper bound for T is IrTypeProjection -> typeArgument.type.run { if (type.isMarkedNullable()) makeNullable() else this } - else -> error("unknown type argument") } } ?: substituteType(type) } @@ -52,21 +51,22 @@ abstract class AbstractIrTypeSubstitutor(private val irBuiltIns: IrBuiltIns) : T } private fun substituteTypeArgument(typeArgument: IrTypeArgument): IrTypeArgument { - if (typeArgument is IrStarProjection) return typeArgument - - require(typeArgument is IrTypeProjection) - - val type = typeArgument.type - if (type is IrSimpleType) { - val classifier = type.classifier - if (classifier is IrTypeParameterSymbol) { - val newArgument = getSubstitutionArgument(classifier) - return if (newArgument is IrTypeProjection) { - makeTypeProjection(newArgument.type, typeArgument.variance) - } else newArgument + when (typeArgument) { + is IrStarProjection -> return typeArgument + is IrTypeProjection -> { + val type = typeArgument.type + if (type is IrSimpleType) { + val classifier = type.classifier + if (classifier is IrTypeParameterSymbol) { + val newArgument = getSubstitutionArgument(classifier) + return if (newArgument is IrTypeProjection) { + makeTypeProjection(newArgument.type, typeArgument.variance) + } else newArgument + } + } + return makeTypeProjection(substituteType(typeArgument.type), typeArgument.variance) } } - return makeTypeProjection(substituteType(typeArgument.type), typeArgument.variance) } } @@ -118,4 +118,4 @@ class IrCapturedTypeSubstitutor( } override fun isEmptySubstitution(): Boolean = oldSubstitution.isEmpty() -} \ No newline at end of file +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt index a41278a880e..ac7211e4ae0 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt @@ -61,8 +61,8 @@ fun IrType.getArrayElementType(irBuiltIns: IrBuiltIns): IrType = argument.type is IrStarProjection -> irBuiltIns.anyNType - else -> - error("Unexpected array argument type: $argument") + null -> + error("Unexpected array argument type: null") } } else { val classifier = this.classOrNull!! diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt index 815726c0245..166eab4253e 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt @@ -150,7 +150,6 @@ private fun makeKotlinType( when (it) { is IrTypeProjection -> TypeProjectionImpl(it.variance, it.type.toKotlinType()) is IrStarProjection -> StarProjectionImpl((classifier.descriptor as ClassDescriptor).typeConstructor.parameters[index]) - else -> error(it) } } return classifier.descriptor.defaultType.replace(newArguments = kotlinTypeArguments).makeNullableAsSpecified(hasQuestionMark) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyTypeRemapper.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyTypeRemapper.kt index 951efa69d53..fdd6db13e87 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyTypeRemapper.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyTypeRemapper.kt @@ -41,10 +41,10 @@ class DeepCopyTypeRemapper( } private fun remapTypeArgument(typeArgument: IrTypeArgument): IrTypeArgument = - if (typeArgument is IrTypeProjection) - makeTypeProjection(this.remapType(typeArgument.type), typeArgument.variance) - else - typeArgument + when (typeArgument) { + is IrTypeProjection -> makeTypeProjection(this.remapType(typeArgument.type), typeArgument.variance) + is IrStarProjection -> typeArgument + } private fun IrTypeAbbreviation.remapTypeAbbreviation() = IrTypeAbbreviationImpl( @@ -53,4 +53,4 @@ class DeepCopyTypeRemapper( arguments.map { remapTypeArgument(it) }, annotations ) -} \ No newline at end of file +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrTypeParameterRemapper.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrTypeParameterRemapper.kt index 2ddea722c58..9995160602c 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrTypeParameterRemapper.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrTypeParameterRemapper.kt @@ -43,10 +43,10 @@ class IrTypeParameterRemapper( ?: this private fun IrTypeArgument.remap() = - if (this is IrTypeProjection) - makeTypeProjection(remapType(type), variance) - else - this + when (this) { + is IrTypeProjection -> makeTypeProjection(remapType(type), variance) + is IrStarProjection -> this + } private fun IrTypeAbbreviation.remap() = IrTypeAbbreviationImpl( diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrTypeUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrTypeUtils.kt index 482b873f7e0..caeb26ee320 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrTypeUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrTypeUtils.kt @@ -100,10 +100,9 @@ fun IrType.substitute(substitutionMap: Map): IrTy } val newArguments = arguments.map { - if (it is IrTypeProjection) { - makeTypeProjection(it.type.substitute(substitutionMap), it.variance) - } else { - it + when (it) { + is IrTypeProjection -> makeTypeProjection(it.type.substitute(substitutionMap), it.variance) + is IrStarProjection -> it } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt index 1c895e329f1..7a662f4528f 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt @@ -987,7 +987,7 @@ fun IrType.remapTypeParameters( it.type.remapTypeParameters(source, target, srcToDstParameterMap), it.variance ) - else -> it + is IrStarProjection -> it } }, annotations diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt index 507337c2871..821b6d2d02f 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt @@ -593,7 +593,6 @@ fun IrTypeArgument.render() = when (this) { is IrStarProjection -> "*" is IrTypeProjection -> "$variance ${type.render()}" - else -> throw AssertionError("Unexpected IrTypeArgument: $this") } internal inline fun Buffer.appendIterableWith( @@ -785,8 +784,6 @@ private fun IrTypeArgument.renderTypeArgument(renderer: RenderIrElementVisitor?, if (variance != Variance.INVARIANT) append(' ') append(type.renderTypeWithRenderer(renderer, verboseErrorTypes)) } - - else -> "IrTypeArgument[$this]" } private fun renderTypeAnnotations(annotations: List, renderer: RenderIrElementVisitor?, verboseErrorTypes: Boolean) = diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SimpleTypeRemapper.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SimpleTypeRemapper.kt index f467390e2c5..e19e3062bbb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SimpleTypeRemapper.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SimpleTypeRemapper.kt @@ -42,10 +42,10 @@ class SimpleTypeRemapper( } private fun remapTypeArgument(typeArgument: IrTypeArgument): IrTypeArgument = - if (typeArgument is IrTypeProjection) - makeTypeProjection(this.remapType(typeArgument.type), typeArgument.variance) - else - typeArgument + when (typeArgument) { + is IrTypeProjection -> makeTypeProjection(this.remapType(typeArgument.type), typeArgument.variance) + is IrStarProjection -> typeArgument + } private fun IrTypeAbbreviation.remapTypeAbbreviation() = IrTypeAbbreviationImpl( diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrFileSerializer.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrFileSerializer.kt index ee9967284a1..2c71c89ea65 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrFileSerializer.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrFileSerializer.kt @@ -374,7 +374,6 @@ open class IrFileSerializer( return when (argument) { is IrStarProjection -> serializeIrStarProjection() is IrTypeProjection -> serializeIrTypeProjection(argument) - else -> TODO("Unexpected type argument kind: $argument") } } @@ -484,7 +483,6 @@ open class IrFileSerializer( kind = when (this) { is IrStarProjection -> IrTypeArgumentKind.STAR is IrTypeProjection -> IrTypeArgumentKind.PROJECTION - else -> error("Unexpected type argument kind: $this") }, variance = (this as? IrTypeProjection)?.variance, type = (this as? IrTypeProjection)?.type?.toIrTypeKey diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/AddFunctionSupertypeToSuspendFunctionLowering.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/AddFunctionSupertypeToSuspendFunctionLowering.kt index 583c6c9aca4..e2374156a2d 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/AddFunctionSupertypeToSuspendFunctionLowering.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/AddFunctionSupertypeToSuspendFunctionLowering.kt @@ -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 }) } -} \ No newline at end of file +} diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ReflectionSupport.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ReflectionSupport.kt index c0f8b3dee77..81a7907f2b4 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ReflectionSupport.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ReflectionSupport.kt @@ -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( diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/SamSuperTypesChecker.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/SamSuperTypesChecker.kt index 4727a8db6d6..ce927e43db6 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/SamSuperTypesChecker.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/SamSuperTypesChecker.kt @@ -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, } }) } -} \ No newline at end of file +} diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUtils2.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUtils2.kt index 12898f6d73c..7fcb57aa6b6 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUtils2.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUtils2.kt @@ -183,7 +183,6 @@ fun IrType.substitute(map: Map): IrType { when (it) { is IrTypeProjection -> makeTypeProjection(it.type.substitute(map), it.variance) is IrStarProjection -> it - else -> error(it) } } IrSimpleTypeImpl(classifier, nullability, newArguments, annotations) diff --git a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ir/irUtils.kt b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ir/irUtils.kt index 03e48bc6396..e0af1929c60 100644 --- a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ir/irUtils.kt +++ b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ir/irUtils.kt @@ -150,7 +150,6 @@ fun IrTypeArgument.upperBound(builtIns: IrBuiltIns): IrType = else builtIns.anyNType } - else -> error("Unknown type argument: ${render()}") } private fun IrClass.getSimpleFunction(name: String): IrSimpleFunctionSymbol? = diff --git a/plugins/parcelize/parcelize-compiler/parcelize.backend/src/org/jetbrains/kotlin/parcelize/ir/irUtils.kt b/plugins/parcelize/parcelize-compiler/parcelize.backend/src/org/jetbrains/kotlin/parcelize/ir/irUtils.kt index 9f579818f73..14bb251a62d 100644 --- a/plugins/parcelize/parcelize-compiler/parcelize.backend/src/org/jetbrains/kotlin/parcelize/ir/irUtils.kt +++ b/plugins/parcelize/parcelize-compiler/parcelize.backend/src/org/jetbrains/kotlin/parcelize/ir/irUtils.kt @@ -194,7 +194,6 @@ fun IrTypeArgument.upperBound(builtIns: IrBuiltIns): IrType = else builtIns.anyNType } - else -> error("Unknown type argument: ${render()}") } private fun IrClass.getSimpleFunction(name: String): IrSimpleFunctionSymbol? =