Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/throwInTry.fir.kt
T
Andrey Zinovyev 06b23d5937 [FIR] Improve the control flow graph around try expressions
1. throw goes to catches instead of main exist block
2. return goes via finally (single level only supported atm)
3. collect non-direct return to retrieve all return expressions easier
2021-08-06 11:49:34 +03:00

89 lines
1.8 KiB
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_EXPRESSION
fun throwInTry_valueInCatch_smartcastAfterTryCatch() {
val s = try {
throw AssertionError()
} catch(e: Throwable) {
"OK"
}
s.length
}
fun throwInTry_valueInFinally_noSmartcastAfterTryCatchFinally() {
val s = try {
throw AssertionError()
} catch(e: Throwable) {
} finally {
"not enough"
}
s.<!UNRESOLVED_REFERENCE!>length<!>
}
fun throwInTry_valueInCatchAndFinally_smartcastAfterTryCatchFinally() {
val s = try {
throw AssertionError()
} catch(e: Throwable) {
"OK"
} finally {
"really"
}
s.length
}
interface A
interface B : A
fun takeB(b: B) {}
fun conditionalThrowInTry_smartcastInTry(a: A) {
try {
if (a !is B) {
throw AssertionError()
}
takeB(a)
} catch (e: Throwable) {}
}
fun conditionalThrowInTry_noSmartcastAfterTryCatch(a: A) {
try {
if (a !is B) {
throw AssertionError()
}
} catch (e: Throwable) {}
takeB(<!ARGUMENT_TYPE_MISMATCH!>a<!>)
}
fun conditionalThrowInTry_rethrow_smartcastAfterTryCatch(a: A) {
try {
if (a !is B) {
throw AssertionError()
}
} catch (e: Throwable) {
throw e
}
takeB(a)
}
fun conditionalThrowInTry_rethrow_smartcastAfterTryCatchFinally(a: A) {
try {
if (a !is B) {
throw AssertionError()
}
} catch (e: Throwable) {
throw e
} finally {}
takeB(<!ARGUMENT_TYPE_MISMATCH!>a<!>)
}
fun conditionalThrowInTry_rethrow_noSmartcastInFinally(a: A) {
try {
if (a !is B) {
throw AssertionError()
}
} catch (e: Throwable) {
throw e
} finally {
takeB(<!ARGUMENT_TYPE_MISMATCH!>a<!>)
}
}