[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
This commit is contained in:
committed by
teamcityserver
parent
7b6dddf012
commit
06b23d5937
Vendored
+2
-2
@@ -113,7 +113,7 @@ fun t7() : Int {
|
||||
catch (<!THROWABLE_TYPE_MISMATCH!>e : Any<!>) {
|
||||
2
|
||||
}
|
||||
<!UNREACHABLE_CODE!>return 1<!> // this is OK, like in Java
|
||||
return 1 // this is OK, like in Java
|
||||
}
|
||||
|
||||
fun t8() : Int {
|
||||
@@ -123,7 +123,7 @@ fun t8() : Int {
|
||||
}
|
||||
catch (<!THROWABLE_TYPE_MISMATCH!>e : Any<!>) {
|
||||
return 1
|
||||
2
|
||||
<!UNREACHABLE_CODE!>2<!>
|
||||
}
|
||||
<!UNREACHABLE_CODE!>return 1<!>
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ fun f2() {
|
||||
finally {
|
||||
<!VAL_REASSIGNMENT!>n<!> = 2
|
||||
}
|
||||
n.hashCode()
|
||||
<!UNINITIALIZED_VARIABLE!>n<!>.hashCode()
|
||||
}
|
||||
|
||||
fun g1(flag: Boolean) {
|
||||
|
||||
@@ -1,222 +0,0 @@
|
||||
fun foo(): Int = 42
|
||||
|
||||
object ThrowInTryWithCatch {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
throw Exception()
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object ThrowInTryWithCatchAndFinally {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
throw Exception()
|
||||
} catch (e: Exception) {
|
||||
} finally {
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object ThrowInFinally {
|
||||
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>private val p: String<!>
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
} finally {
|
||||
throw Exception()
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object RethrowInCatch {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
throw e
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object RethrowInCatchWithFinally {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
throw e
|
||||
} finally {
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object InnerTryWithCatch {
|
||||
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>private val p: String<!>
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
throw e
|
||||
} catch (ee: Exception) {
|
||||
}
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object InnerTryWithFinally {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
throw e
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object InnerTryWithCatchAndFinally {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
throw e
|
||||
} catch (ee: Exception) {
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object InnerCatch {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
foo()
|
||||
} catch (ee: Exception) {
|
||||
throw ee
|
||||
}
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object InnerCatchWithFinally {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
foo()
|
||||
} catch (ee: Exception) {
|
||||
throw ee
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object InnerCatchOuterRethrow {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
foo()
|
||||
} catch (ee: Exception) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object InnerCatchOuterRethrowWithFinally {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
foo()
|
||||
} catch (ee: Exception) {
|
||||
throw e
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object InnerFinally {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
foo()
|
||||
} finally {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
object InnerFinallyWithCatch {
|
||||
private val p: String
|
||||
|
||||
init {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
foo()
|
||||
} catch (ee: Exception) {
|
||||
} finally {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
p = "OK"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
fun foo(): Int = 42
|
||||
|
||||
object ThrowInTryWithCatch {
|
||||
|
||||
@@ -43,7 +43,7 @@ fun t3() : Int {
|
||||
finally {
|
||||
doSmth(3)
|
||||
}
|
||||
}
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun t4() : Int {
|
||||
try {
|
||||
@@ -52,7 +52,7 @@ fun t4() : Int {
|
||||
catch (e: UnsupportedOperationException) {
|
||||
doSmth(2)
|
||||
}
|
||||
}
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
fun t5() : Int {
|
||||
try {
|
||||
|
||||
@@ -61,7 +61,7 @@ fun conditionalThrowInTry_rethrow_smartcastAfterTryCatch(a: A) {
|
||||
} catch (e: Throwable) {
|
||||
throw e
|
||||
}
|
||||
takeB(<!ARGUMENT_TYPE_MISMATCH!>a<!>)
|
||||
takeB(a)
|
||||
}
|
||||
|
||||
fun conditionalThrowInTry_rethrow_smartcastAfterTryCatchFinally(a: A) {
|
||||
|
||||
Reference in New Issue
Block a user