K2: fix enhancement building for Java methods with type parameters

Before this commit, we copied each type parameter during method
enhancement, while not copying the symbol. This led to symbol clashes
in MPP scenarios and various other problems.

Now we create a fully-functional type parameter copy in enhancement
and perform a substitution of old type parameters with new ones
in receiver type, value parameter types, return type,
and type parameter upper bounds.

#KT-59766 Fixed
#KT-59738 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-07-12 15:59:05 +02:00
committed by Space Team
parent 52068e11ee
commit c350280e64
7 changed files with 110 additions and 10 deletions
@@ -0,0 +1,42 @@
// LANGUAGE: +MultiPlatformProjects
// ISSUE: KT-59766
// WITH_STDLIB
// TARGET_BACKEND: JVM_IR
// FULL_JDK
// MODULE: lib-jvm
// FILE: lib.kt
import java.util.concurrent.*
fun <T> CompletionStage<T>.foo() {
handle { value, exception ->
}
}
// MODULE: jvm()()(lib-jvm)
// FILE: jvm.kt
package kotlinx.coroutines.future
import java.util.concurrent.*
import java.util.function.*
fun <T> CompletionStage<T>.asDeferred() {
handle { value, exception ->
}
}
class ContinuationHandler<T> : BiFunction<T?, Throwable?, Unit> {
override fun apply(result: T?, exception: Throwable?) {
}
}
fun box(): String {
val handler = ContinuationHandler<String>()
CompletableFuture<String>().asDeferred()
return "OK"
}