[K/N] Handle Unit? and Nothing? correctly in finally transformation
^KT-52985
This commit is contained in:
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user