Fix runtime CCE in case of out-projected SAM

Probably, when NI is there this fix will become unnecessary because
there will be no approximation applied, thus the value parameter
will remain Hello<#Captured> instead of Nothing

 #KT-17171 Fixed
This commit is contained in:
Denis Zharkov
2018-02-12 12:09:17 +03:00
parent 6baf937a52
commit c47c1c5ffd
7 changed files with 113 additions and 11 deletions
@@ -0,0 +1,60 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// 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");
}
}
// FILE: main.kt
import example.SomeJavaClass
fun box(): String {
val a: SomeJavaClass<out String> = SomeJavaClass()
var result = "fail"
// 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 {
result = it
}
if (result != "OK") return "fail 1: $result"
result = "fail"
a + {
result = it
}
if (result != "OK") return "fail 2: $result"
result = "fail"
a[{
result = it
}]
if (result != "OK") return "fail 3: $result"
return "OK"
}