Files
kotlin/compiler/testData/codegen/boxAgainstJava/sam/kt11519.kt
Dmitry Petrov d27593aeda 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'.
2020-01-03 15:32:44 +03:00

41 lines
800 B
Kotlin
Vendored

// SKIP_JDK6
// FILE: Custom.java
class Custom<K, V> {
private K k;
private V v;
public Custom(K k, V v) {
this.k = k;
this.v = v;
}
public interface MBiConsumer<T, U> {
void accept(T t, U u);
}
public void forEach(MBiConsumer<? super K, ? super V> action) {
action.accept(k, v);
}
}
// FILE: 1.kt
import java.util.Arrays
fun box(): String {
val instance = Custom<String, String>("O", "K")
var result = "fail"
instance.forEach { a, b ->
result = a + b
}
val superInterfaces = Arrays.toString((Class.forName("_1Kt\$box$1")).genericInterfaces)
if (superInterfaces != "[Custom\$MBiConsumer<java.lang.String, java.lang.String>]") {
return "fail: $superInterfaces"
}
return result
}