Do not force coercion to Unit for nullable lambda return type

#KT-41005 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-08-11 23:17:01 +03:00
parent d9bac4d5e4
commit aafe41cf7a
10 changed files with 86 additions and 1 deletions
@@ -0,0 +1,22 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: TestJ.java
public class TestJ {
public static <T> In<T> materialize() {
return null;
}
}
// FILE: test.kt
class In<in T>
fun <T> inferred(e: In<T>?, l: () -> T): T = l()
fun box(): String {
// coercion to Unit for T!
val inferred = (inferred(TestJ.materialize<Unit>(), { null })).toString()
return if (inferred == "kotlin.Unit") "OK" else "fail : $inferred"
}
@@ -0,0 +1,7 @@
fun <T> nullableK(m: () -> T?) = m()
fun box(): String {
// no coercion to Unit for T?
val nullableK = (nullableK<Unit> { null }).toString()
return if (nullableK == "null") "OK" else "fail: $nullableK"
}