From 03613d4708719d183180fda844dfa9414421b2b8 Mon Sep 17 00:00:00 2001 From: Jiaxiang Chen Date: Fri, 28 Feb 2020 00:37:34 -0800 Subject: [PATCH] JVM_IR: preserve old backend's logic for special mutable collection class stub methods --- .../jvm/lower/CollectionStubMethodLowering.kt | 14 +++++++++++++- .../implementCollectionThroughKotlin.kt | 1 - 2 files changed, 13 insertions(+), 2 deletions(-) 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