diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt index 33ab9f26323..a4c549785ce 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt @@ -184,8 +184,20 @@ internal class CollectionStubComputer(val context: JvmBackendContext) { val readOnlyClass: IrClassSymbol, val mutableClass: IrClassSymbol ) { + // Preserve old backend's logic to generate stubs for special cases where a mutable method + // has the same JVM signature as the immutable method. See KT-36724 for more details. + private val specialCaseStubSignaturesForOldBackend = setOf( + "listIterator()Ljava/util/ListIterator;", + "listIterator(I)Ljava/util/ListIterator;", + "subList(II)Ljava/util/List;" + ) + val mutableOnlyMethods: Collection by lazy { - val readOnlyMethodSignatures = readOnlyClass.functions.map { getSignature(it.owner) }.toHashSet() + val readOnlyMethodSignatures = readOnlyClass + .functions + .map { getSignature(it.owner) } + .filter { it !in specialCaseStubSignaturesForOldBackend } + .toHashSet() mutableClass.functions .map { it.owner } .filter { getSignature(it) !in readOnlyMethodSignatures } diff --git a/compiler/testData/codegen/box/collections/implementCollectionThroughKotlin.kt b/compiler/testData/codegen/box/collections/implementCollectionThroughKotlin.kt index d9b0daa9145..ce86c6a851c 100644 --- a/compiler/testData/codegen/box/collections/implementCollectionThroughKotlin.kt +++ b/compiler/testData/codegen/box/collections/implementCollectionThroughKotlin.kt @@ -1,5 +1,4 @@ // IGNORE_BACKEND_FIR: JVM_IR -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // FILE: J.java