Add additional test cases and notes for KT44429

This commit is contained in:
Ivan Kylchik
2023-03-07 21:37:39 +01:00
committed by Space Team
parent f0d4220ad1
commit d2e92fd70d
17 changed files with 153 additions and 8 deletions
+13
View File
@@ -5,6 +5,10 @@
package test
inline fun <T> takeT(t: T) {}
inline fun <T : Any> takeTSuperAny(t: T) {}
inline fun <T, U : T> takeU(u: U) {}
inline fun <T, U : T, R : U> takeR(r: R) {}
inline fun <A, B, T : Map<A, List<B>>> takeTWithMap(t: T) {}
// FILE: 2.kt
import test.*
@@ -12,5 +16,14 @@ import test.*
fun box(): String {
val f = { null } as () -> Int
takeT(f())
// Without fix we are going to get following instructions
// CHECKCAST java/lang/Number
// INVOKEVIRTUAL java/lang/Number.intValue ()I // <- this one leads to NPE
takeTSuperAny(f())
takeU(f())
takeR(f())
val g = { null } as () -> Map<Int, List<String>>
takeTWithMap(g())
return "OK"
}
@@ -0,0 +1,29 @@
// TARGET_BACKEND: JVM
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
// Following examples expected to fail
inline fun <T : Int> takeTFail(t: T) {}
inline fun <T : Int, U : T> takeUSuperInt(u: U) {}
// FILE: 2.kt
import test.*
inline fun <reified T> assertThrows(block: () -> Unit) {
try {
block.invoke()
} catch (t: Throwable) {
if (t is T) return
throw t
}
throw AssertionError("Exception was expected")
}
fun box(): String {
val f = { null } as () -> Int
assertThrows<NullPointerException> { takeTFail(f()) }
assertThrows<NullPointerException> { takeUSuperInt(f()) }
return "OK"
}