From 58f8e25bfe29330be51003ab6e9d472125bb90eb Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 24 May 2023 10:12:18 +0300 Subject: [PATCH] [JVM IR] Generate mutable lower bound type for flexible IR types --- .../kotlin/backend/jvm/ir/IrJvmFlexibleType.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrJvmFlexibleType.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrJvmFlexibleType.kt index 3b3a8be5fb5..960a4921423 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrJvmFlexibleType.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrJvmFlexibleType.kt @@ -36,6 +36,23 @@ private class IrJvmFlexibleTypeImpl( // No change in classifier is needed for mutability because type's classifier is set to the lower bound anyway // (see TypeTranslator.translateType). kotlinType = null + if (mutability) { + val klass = classifier?.owner as? IrClass + ?: error("Mutability-flexible type's classifier is not a class: ${irType.render()}") + val readonlyClassFqName = FlexibleTypeBoundsChecker.getBaseBoundFqNameByMutability(klass.fqNameWhenAvailable!!) + classifier = when (readonlyClassFqName) { + StandardNames.FqNames.iterable -> builtIns.mutableIterableClass + StandardNames.FqNames.iterator -> builtIns.mutableIteratorClass + StandardNames.FqNames.listIterator -> builtIns.mutableListIteratorClass + StandardNames.FqNames.list -> builtIns.mutableListClass + StandardNames.FqNames.collection -> builtIns.mutableCollectionClass + StandardNames.FqNames.set -> builtIns.mutableSetClass + StandardNames.FqNames.map -> builtIns.mutableMapClass + StandardNames.FqNames.mapEntry -> builtIns.mutableMapEntryClass + else -> error("Mutability-flexible type with unknown classifier: ${irType.render()}, FQ name: $readonlyClassFqName") + } + } + } override val upperBound: IrSimpleType