PSI2IR: SAM conversion in method arguments of out-projected Java classes
It uses the same logic as an old back-end (see SamType#createByValueParameter and genericSamProjectedOut.kt), split into two parts: 1. When inserting SAM casts, use SamType#createByValueParamerer to get the target SAM type. 2. When inserting implicit casts, cast SAM conversions as arguments of methods of out-projected types to the original type of value parameter instead of 'Nothing'.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: genericSamProjectedOut.kt
|
||||
import example.SomeJavaClass
|
||||
|
||||
fun test(a: SomeJavaClass<out String>) {
|
||||
// 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[{}]
|
||||
}
|
||||
|
||||
// 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 void plus(Hello<A> hello) {
|
||||
((Hello)hello).invoke("OK");
|
||||
}
|
||||
|
||||
public void get(Hello<A> hello) {
|
||||
((Hello)hello).invoke("OK");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user