Files
kotlin/compiler/testData/codegen/box/javaInterop/notNullAssertions/enhancedNullability/inFunctionWithExpressionBodyWithJavaGeneric.kt
Dmitry Petrov e308dd02d8 Add box tests for new nullability assertions
(cherry picked from commit 0a84c3f)
2017-10-24 16:03:23 +03:00

34 lines
645 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// STRICT_JAVA_NULLABILITY_ASSERTIONS
// 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 {
public <T> @NotNull T nullT() {
return null;
}
public void test() {
TestKt.withAssertion(this);
}
}