FIR: Use intersection of all upper bounds for parameterized types in

ConeKotlinType.canBeNull.

^KT-45903 In progress
This commit is contained in:
Mark Punzalan
2021-04-05 23:08:18 +00:00
committed by TeamCityServer
parent ac85f9d983
commit 21a3a14289
25 changed files with 417 additions and 3 deletions
@@ -0,0 +1,26 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM, JVM_IR
// Note: This fails on non-FIR because of KT-45903 (missing not-null assertion on argument).
// FILE: typeParameterWithMixedNullableAndNotNullableBounds.kt
fun <T> f(x: T): Int where T : CharSequence?, T : Comparable<T> {
try {
return x.compareTo(x)
} catch (e: NullPointerException) {
return 42
}
}
fun box() = try {
val r = f(J.s())
if (r == 42) "FAIL" else "Unexpected, x.compareTo(x) should have NPE'd"
} catch (e: NullPointerException) {
"OK"
}
// FILE: J.java
public class J {
public static String s() { return null; }
}
@@ -0,0 +1,22 @@
// TARGET_BACKEND: JVM
// FILE: typeParameterWithMultipleNotNullableBounds.kt
fun <T> f(x: T): Int where T : CharSequence, T : Comparable<T> {
try {
return x.compareTo(x)
} catch (e: NullPointerException) {
return 42
}
}
fun box() = try {
val r = f(J.s())
if (r == 42) "FAIL" else "Unexpected, x.compareTo(x) should have NPE'd"
} catch (e: NullPointerException) {
"OK"
}
// FILE: J.java
public class J {
public static String s() { return null; }
}
@@ -0,0 +1,12 @@
// TARGET_BACKEND: JVM
// FILE: typeParameterWithMultipleNullableBounds.kt
fun <T> f(x: T): Int? where T : CharSequence?, T : Comparable<T>? {
return x?.compareTo(x)
}
fun box() = f(J.s()) ?: "OK"
// FILE: J.java
public class J {
public static String s() { return null; }
}