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:
@@ -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!!
|
||||
}
|
||||
@@ -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!!
|
||||
}
|
||||
Reference in New Issue
Block a user