KT-47939 fun interface constructor reference should throw NPE for null

This commit is contained in:
Dmitry Petrov
2021-12-07 15:09:24 +03:00
committed by TeamCityServer
parent e5eee9bab9
commit 0ccd7a7e0c
15 changed files with 245 additions and 102 deletions
@@ -0,0 +1,32 @@
// !LANGUAGE: +KotlinFunInterfaceConstructorReference
// WITH_RUNTIME
// TARGET_BACKEND: JVM
// DONT_TARGET_EXACT_BACKEND: JVM
// ^ old JVM BE generates bogus code
// FILE: funInterfaceConstructorThrowsNpe.kt
fun interface KSupplier<T> {
fun get(): T
}
val ks: (() -> String) -> KSupplier<String> =
::KSupplier
fun box(): String {
try {
ks(J.fn)
return "ks(null) should throw NPE"
} catch (e: NullPointerException) {
return "OK"
}
}
// FILE: J.java
import kotlin.jvm.functions.Function0;
public class J {
public static Function0<String> fn = null;
}