Files
kotlin-fork/compiler/testData/codegen/box/javaInterop/notNullAssertions/enhancedNullability/inFunctionWithExpressionBodyWithJavaGeneric.kt
T
2021-08-17 21:38:01 +03:00

36 lines
747 B
Kotlin
Vendored

// !LANGUAGE: +StrictJavaNullabilityAssertions -ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// See KT-8135
// We could generate runtime assertion on call site for 'generic<NOT_NULL_TYPE>()' below.
// FILE: box.kt
fun box(): String {
try {
J().test()
return "OK"
}
catch (e: Throwable) {
return "Fail: SHOULD NOT throw"
}
}
// FILE: test.kt
fun withAssertion(j: J) = generic<String?>(j)
fun <T> generic(j: J) = j.nullT<T>()
// FILE: J.java
import org.jetbrains.annotations.NotNull;
public class J {
@NotNull
public <T> T nullT() {
return null;
}
public void test() {
TestKt.withAssertion(this);
}
}