mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
Add box tests for new nullability assertions
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// STRICT_JAVA_NULLABILITY_ASSERTIONS
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
try {
|
||||
J().test()
|
||||
return "Fail: should throw"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun withAssertion(j: J) = j.nullString()
|
||||
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class J {
|
||||
public @NotNull String nullString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
TestKt.withAssertion(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// STRICT_JAVA_NULLABILITY_ASSERTIONS
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
try {
|
||||
outer()
|
||||
return "Fail: should throw"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun outer() {
|
||||
fun withAssertion() = J().nullString()
|
||||
withAssertion() // NB not used itself
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class J {
|
||||
public @NotNull String nullString() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// STRICT_JAVA_NULLABILITY_ASSERTIONS
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
try {
|
||||
J().test()
|
||||
return "Fail: should throw"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun withAssertion(j: J) {
|
||||
val x = j.nullString()
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class J {
|
||||
public @NotNull String nullString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
TestKt.withAssertion(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// STRICT_JAVA_NULLABILITY_ASSERTIONS
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
try {
|
||||
J().test()
|
||||
return "Fail: should throw"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
class C {
|
||||
val withAssertion = J().nullString()
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class J {
|
||||
public @NotNull String nullString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object test() {
|
||||
return new C();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// STRICT_JAVA_NULLABILITY_ASSERTIONS
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
try {
|
||||
J().test()
|
||||
return "Fail: should throw"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
val withAssertion get() = J().nullString()
|
||||
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class J {
|
||||
public @NotNull String nullString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
TestKt.getWithAssertion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// STRICT_JAVA_NULLABILITY_ASSERTIONS
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
try {
|
||||
J().test()
|
||||
return "Fail: should throw"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
val withAssertion = J().nullString()
|
||||
|
||||
fun clinitTrigger() {}
|
||||
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class J {
|
||||
public @NotNull String nullString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
TestKt.clinitTrigger();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user