JVM IR: fix incorrect type of IrCheckNotNull intrinsic

It is not correct to assume that arg0 has been generated to have the
same IrType as the whole expression.

The reason it only backfired in throwing exceptions probably has to do
with the fact that visitThrow might be the only place in
ExpressionCodegen right now which uses the IrType from PromisedValue to
make a decision on whether to generate checkcast.

It seems suspicious that ExpressionCodegen.visitFieldAccess/visitCall
return PromisedValue whose IrType mentions type parameters which are
declared outside of the call site, but that should probably be
investigated separately.

 #KT-48440 Fixed
This commit is contained in:
Alexander Udalov
2021-08-31 02:38:50 +02:00
parent 1d5501c047
commit cc52832943
11 changed files with 130 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
// IGNORE_BACKEND: WASM
fun test(): String {
var exception: Throwable? = null
val f = {
exception = IllegalStateException("OK")
}
f()
if (exception != null) {
throw exception!!
} else {
return "Fail"
}
}
fun box(): String = try {
test()
} catch (e: IllegalStateException) {
e.message!!
}
+22
View File
@@ -0,0 +1,22 @@
// IGNORE_BACKEND: WASM
fun <T> id(t: T): T = t
fun test(b: Boolean): String {
var exception: Throwable? = null
if (b) {
exception = IllegalStateException("OK")
}
if (exception != null) {
throw id(exception)!!
} else {
return "Fail"
}
}
fun box(): String = try {
test(true)
} catch (e: IllegalStateException) {
e.message!!
}