Files
kotlin-fork/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

48 lines
1008 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_STDLIB
// FILE: genericSamProjectedOut.kt
import example.SomeJavaClass
fun test() {
var a: SomeJavaClass<out String> = SomeJavaClass()
// a::someFunction parameter has type of Nothing
// while it's completely safe to pass a lambda for a SAM
// since Hello is effectively contravariant by its parameter
a.someFunction {}
a + {}
a[{}]
a += {}
a[0] = {}
}
// FILE: example/Hello.java
package example;
@FunctionalInterface
public interface Hello<A> {
void invoke(A a);
}
// FILE: example/SomeJavaClass.java
package example;
public class SomeJavaClass<A> {
public void someFunction(Hello<A> hello) {
((Hello)hello).invoke("OK");
}
public SomeJavaClass<A> plus(Hello<A> hello) {
((Hello)hello).invoke("OK");
return this;
}
public void get(Hello<A> hello) {
((Hello)hello).invoke("OK");
}
public void set(int i, Hello<A> hello) {
((Hello)hello).invoke("OK");
}
}