Files
kotlin-fork/compiler/testData/codegen/box/sam/kt11696.kt
T
Alexander Udalov b2005302dc JVM, JVM IR: erase generic SAM supertypes
Also, do not try to use invokedynamic on SAM calls with intersection
types, because intersection type is not allowed as an immediate type
projection of a supertype, and constructing a fake override in
LambdaMetafactoryArgumentsBuilder led to an exception. This fixes the
problem which was worked around earlier in e6c089ef, effectively
reverting that commit.

The main motivation for this change is that LambdaMetafactory also
doesn't generate generic signature for SAM wrapper classes at runtime.
Since these classes are synthetic, nobody should rely on the fact that
they have generic supertypes, which was observable only via Java
reflection.

 #KT-46149 Fixed
 #KT-46238 Fixed
2021-04-22 10:53:15 +02:00

42 lines
941 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_RUNTIME
// SAM_CONVERSIONS: CLASS
// ^ test checks reflection for synthetic classes
// MODULE: lib
// FILE: Promise.java
import org.jetbrains.annotations.NotNull;
interface Consumer<T> {
void consume(T t);
}
public abstract class Promise<T> {
@NotNull
public abstract Promise<T> done(@NotNull Consumer<? super T> done);
}
// MODULE: main(lib)
// FILE: 1.kt
class User {
fun use(promise: Promise<*>): Promise<*> {
promise.done { }
return promise
}
}
fun box(): String {
var result = ""
User().use(
object : Promise<CharSequence>() {
override fun done(x: Consumer<in CharSequence?>): Promise<CharSequence> {
result = x.javaClass.genericInterfaces[0].toString()
return this
}
}
)
if (result != "interface Consumer") return "fail: $result"
return "OK"
}