JVM_IR: skip SAM lambdas when computing enclosing method of objects

This is what Java 15+ does, and it permits accessing captured type
parameters via reflection. The alternative is to emit generic signatures
on the lambda methods, but that was disabled and I have no clue why.

^KT-52417 Fixed
This commit is contained in:
pyos
2022-05-24 09:23:41 +02:00
committed by Alexander Udalov
parent f81d47bad6
commit 27c51f5f88
21 changed files with 211 additions and 6 deletions
+18
View File
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// WITH_STDLIB
package test
abstract class TypeToken<T>
fun interface I {
fun foo(): String
}
fun <T> foo() =
I {
(object : TypeToken<T>() {})::class.java.genericSuperclass.toString()
}.foo()
fun box(): String =
foo<String>().let { if (it == "test.TypeToken<T>") "OK" else it }
@@ -0,0 +1,28 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// WITH_STDLIB
// FILE: 1.kt
package test
abstract class TypeToken<U>
// Although V is not reified, if the object happens to be regenerated, V will be replaced with its value in signatures
inline fun <V> typeTokenOf(crossinline forceRegeneration: () -> Unit = {}) =
object : TypeToken<V>() {
fun unused() = forceRegeneration()
}
// FILE: 2.kt
import test.*
fun interface I {
fun foo(): String
}
fun <T> foo() =
I {
typeTokenOf<T>()::class.java.genericSuperclass.toString()
}.foo()
fun box(): String =
foo<String>().let { if (it == "test.TypeToken<T>") "OK" else it }