JVM IR: fix generic signatures of suspend function references

Using `kotlin.jvm.functions.Function{n+1}` (via
`getJvmSuspendFunctionClass`) for suspend functions was wrong in the
function reference lowering, because we didn't adapt the parameter types
by transforming the last type to Continuation and adding Object, and
generic signature ended up being incorrect.

Actually there was no need to use `kotlin.jvm.functions.Function{n+1}`
at all. We can just use the built-in
`kotlin.coroutines.SuspendFunction{n}` as a supertype, and it will be
mapped correctly later in codegen. It's not even needed to add the
`kotlin.coroutines.jvm.internal.SuspendFunction` marker manually, since
it's also handled by the codegen (see `IrTypeMapper.mapClassSignature`).

 #KT-48732 Fixed
This commit is contained in:
Alexander Udalov
2021-10-01 02:07:00 +02:00
parent 43a83dd07a
commit 31ba7f24b1
6 changed files with 42 additions and 5 deletions
@@ -0,0 +1,17 @@
// TARGET_BACKEND: JVM
// WITH_COROUTINES
// WITH_RUNTIME
suspend fun id(x: String): String = x
val f: suspend (String) -> String = ::id
fun box(): String {
val actual = f.javaClass.genericInterfaces.toList().toString()
val expected = "[" +
"kotlin.jvm.functions.Function2<java.lang.String, kotlin.coroutines.Continuation<? super java.lang.String>, java.lang.Object>, " +
"interface kotlin.coroutines.jvm.internal.SuspendFunction" +
"]"
return if (expected == actual) "OK" else "Fail: $actual"
}