Files
kotlin-fork/compiler/testData/codegen/box/casts/kt54581.kt
T
pyos 65c153a722 JVM: consider casts of null to be redundant
These should only have ever been necessary for field type inference in
coroutines, which should have been fixed by 0fc676a20c.

Unlike 903a5d69a4, this time the change is in an optimization pass.
Advantage: optimization passes have a closer to the JVM view of the
bytecode, which makes this change significantly more likely to be correct.
Disadvantage: technically we don't really guarantee optimization passes
other than FixStack will run at all. For KT-54581 this is 100% fine
since the problem itself is caused by redundant checkcast elimination in
the first place (otherwise there would've been a redundant cast to
String), but for KT-53146 this means the fix is somewhat incidental and
not necessarily guaranteed.

^KT-53146 Fixed
^KT-54581 Fixed
2022-10-24 11:11:21 +02:00

17 lines
293 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
fun box(): String {
val k = tryOrNull { "K" }
return "O$k"
}
private inline fun <T> tryOrNull(action: () -> T): T? =
try {
action()
} catch (e: Throwable) {
when {
else -> {
null
}
}
}