Add codegen tests for old behavior of null checks

#KT-22275
This commit is contained in:
Alexander Udalov
2020-01-22 15:58:49 +01:00
parent 632fe18db6
commit 2fca7f1a54
15 changed files with 160 additions and 127 deletions
@@ -0,0 +1,15 @@
// !API_VERSION: 1.3
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
fun box(): String {
val s: String? = null
try {
s!!
return "Fail: KNPE should have been thrown"
} catch (e: Throwable) {
if (e::class != KotlinNullPointerException::class) return "Fail: exception class should be KNPE: ${e::class}"
return "OK"
}
}
@@ -1,4 +1,3 @@
// !API_VERSION: LATEST
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
@@ -0,0 +1,23 @@
// !API_VERSION: 1.3
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.java
import org.jetbrains.annotations.NotNull;
public class A {
@NotNull
public static String foo() { return null; }
}
// FILE: test.kt
fun box(): String {
try {
val s: String = A.foo()
return "Fail: ISE should have been thrown"
} catch (e: Throwable) {
if (e::class != IllegalStateException::class) return "Fail: exception class should be ISE: ${e::class}"
return "OK"
}
}
@@ -1,4 +1,3 @@
// !API_VERSION: LATEST
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.java
@@ -0,0 +1,26 @@
// !API_VERSION: 1.3
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.java
public class A {
public static void test() {
new B().foo(null);
}
}
// FILE: test.kt
class B {
fun foo(s: String) {}
}
fun box(): String {
try {
A.test()
return "Fail: IAE should have been thrown"
} catch (e: Throwable) {
if (e::class != IllegalArgumentException::class) return "Fail: exception class should be IAE: ${e::class}"
return "OK"
}
}
@@ -1,4 +1,3 @@
// !API_VERSION: LATEST
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.java