JVM_IR KT-47398 handle @EnhancedNullability String subject as in 1.0
This commit is contained in:
committed by
teamcityserver
parent
c26d71c4ef
commit
0104b1275f
@@ -0,0 +1,75 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: enhancedNullability.kt
|
||||
fun testEmpty() {
|
||||
when (J.nullString()) {
|
||||
}
|
||||
}
|
||||
|
||||
fun testSingle() {
|
||||
try {
|
||||
var q = "other"
|
||||
when (J.nullString()) {
|
||||
"a" -> q = "A"
|
||||
}
|
||||
throw Exception("Should throw NPE, got '$q'")
|
||||
} catch (e: NullPointerException) {
|
||||
}
|
||||
}
|
||||
|
||||
fun testElseOnly() {
|
||||
var q = "other"
|
||||
when (J.nullString()) {
|
||||
else -> q = "A"
|
||||
}
|
||||
if (q != "A") {
|
||||
throw Exception("Expected: 'A', got '$q'")
|
||||
}
|
||||
}
|
||||
|
||||
fun testSmall() {
|
||||
try {
|
||||
val q = when (J.nullString()) {
|
||||
"a" -> "A"
|
||||
else -> "other"
|
||||
}
|
||||
throw Exception("Should throw NPE, got '$q'")
|
||||
} catch (e: NullPointerException) {
|
||||
}
|
||||
}
|
||||
|
||||
fun testBigger() {
|
||||
try {
|
||||
val q = when (J.nullString()) {
|
||||
"a" -> "A"
|
||||
"b" -> "B"
|
||||
"c" -> "C"
|
||||
"d" -> "D"
|
||||
"e" -> "E"
|
||||
"f" -> "F"
|
||||
"g" -> "G"
|
||||
"h" -> "H"
|
||||
else -> "other"
|
||||
}
|
||||
throw Exception("Should throw NPE, got '$q'")
|
||||
} catch (e: NullPointerException) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
testEmpty()
|
||||
testSingle()
|
||||
testElseOnly()
|
||||
testSmall()
|
||||
testBigger()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class J {
|
||||
public static @NotNull String nullString() { return null; }
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: flexibleNullability.kt
|
||||
fun testEmpty() {
|
||||
when (J.nullString()) {
|
||||
}
|
||||
}
|
||||
|
||||
fun testSingle() {
|
||||
var q = "other"
|
||||
when (J.nullString()) {
|
||||
"a" -> q = "A"
|
||||
}
|
||||
if (q != "other") {
|
||||
throw Exception("Expected 'other', got '$q'")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun testElseOnly() {
|
||||
var q = "other"
|
||||
when (J.nullString()) {
|
||||
else -> q = "A"
|
||||
}
|
||||
if (q != "A") {
|
||||
throw Exception("Expected: 'A', got '$q'")
|
||||
}
|
||||
}
|
||||
|
||||
fun testSmall() {
|
||||
val q = when (J.nullString()) {
|
||||
"a" -> "A"
|
||||
else -> "other"
|
||||
}
|
||||
if (q != "other") {
|
||||
throw Exception("Expected 'other', got '$q'")
|
||||
}
|
||||
}
|
||||
|
||||
fun testBigger() {
|
||||
val q = when (J.nullString()) {
|
||||
"a" -> "A"
|
||||
"b" -> "B"
|
||||
"c" -> "C"
|
||||
"d" -> "D"
|
||||
"e" -> "E"
|
||||
"f" -> "F"
|
||||
"g" -> "G"
|
||||
"h" -> "H"
|
||||
else -> "other"
|
||||
}
|
||||
if (q != "other") {
|
||||
throw Exception("Expected 'other', got '$q'")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
testEmpty()
|
||||
testSingle()
|
||||
testElseOnly()
|
||||
testSmall()
|
||||
testBigger()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public static String nullString() { return null; }
|
||||
}
|
||||
Reference in New Issue
Block a user