[K/N] Handle Unit? and Nothing? correctly in finally transformation

^KT-52985
This commit is contained in:
Pavel Kunyavskiy
2022-06-28 15:25:34 +02:00
committed by Space
parent dc48d722fe
commit c1ec1d9d4c
10 changed files with 80 additions and 3 deletions
@@ -0,0 +1,32 @@
inline fun <T> withCatch(block: () -> T?) : T? {
try {
return block()
} catch (e: NullPointerException) {
return null
} finally {
}
}
fun f1() = withCatch<Int> { null }
fun f2() = withCatch<Unit> { null }
fun f3() = withCatch<Nothing> { null }
inline fun <T> withOutCatch(block: () -> T?) : T? {
try {
return block()
} finally {
}
}
fun f4() = withOutCatch<Int> { null }
fun f5() = withOutCatch<Unit> { null }
fun f6() = withOutCatch<Nothing> { null }
fun box() : String {
if (f1() != null) return "FAIL1"
if (f2() != null) return "FAIL2"
if (f3() != null) return "FAIL3"
if (f4() != null) return "FAIL4"
if (f5() != null) return "FAIL5"
if (f6() != null) return "FAIL6"
return "OK"
}