Looking at the updated example, I would adapt the above proposals as follows (again, the former more for illustrative purposes, I would suggest going for the latter one in production code):
fun f() {
val x = IllegalStateException()
val result = x !is IllegalStateException && throw x
print(result)
}
and
fun f() {
val x = IllegalStateException()
if (x !is IllegalStateException) throw x
val result = false
print(result)
}
which in this simple example you could of course reduce to
fun f() {
val x = IllegalStateException()
if (x !is IllegalStateException) throw x
print(false)
}
Perhaps I am missing more context here, however in these small examples, result
is effectively a constant, as it only ever is false
. In all other cases, we currently omit executing the entire path where result
is used (since we throw the exception before that).