Generate proper exception table

Don't forget to split nested try blocks without finally block
 on generating finally blocks from outer ones.

 #KT-31923 InProgress
This commit is contained in:
Mikhael Bogdanov
2019-06-11 11:29:52 +02:00
parent 078cfc02a5
commit c335015c05
20 changed files with 752 additions and 65 deletions
@@ -0,0 +1,31 @@
// IGNORE_BACKEND_FIR: JVM_IR
var result = ""
fun test() {
try {
for (z in 1..2) {
try {
result += "try"
break
} catch (fail: Throwable) {
result += " catch"
}
}
result += " after loop"
} finally {
result += " finally"
throw RuntimeException()
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
}
return if (result == "try after loop finally") "OK" else "fail: $result"
}
@@ -0,0 +1,31 @@
// IGNORE_BACKEND_FIR: JVM_IR
var result = ""
fun test() {
try {
for (z in 1..2) {
try {
result += "try "
continue
} catch (fail: Throwable) {
result += " catch"
}
}
result += "after loop"
} finally {
result += " finally"
throw RuntimeException()
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
}
return if (result == "try try after loop finally") "OK" else "fail: $result"
}
+30
View File
@@ -0,0 +1,30 @@
// !LANGUAGE: +ProperFinally
// IGNORE_BACKEND_FIR: JVM_IR
var result = ""
fun test() {
for (z in 1..2) {
try {
try {
result += "try"
break
} catch (fail: Throwable) {
result += " catch"
}
} finally {
result += " finally"
throw RuntimeException()
}
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
}
return if (result == "try finally") "OK" else "fail: $result"
}
@@ -0,0 +1,30 @@
// !LANGUAGE: +ProperFinally
// IGNORE_BACKEND_FIR: JVM_IR
var result = ""
fun test() {
for (z in 1..2) {
try {
try {
result += "try"
continue
} catch (fail: Throwable) {
result += "catch"
}
} finally {
result += " finally"
throw RuntimeException()
}
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
}
return if (result == "try finally") "OK" else "fail: $result"
}
+27
View File
@@ -0,0 +1,27 @@
// !LANGUAGE: +ProperFinally
var result = ""
fun test() {
try {
try {
result += "try"
return
} catch (fail: Throwable) {
result += " catch"
}
} finally {
result += " finally"
throw RuntimeException()
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
}
return if (result == "try finally") "OK" else "fail: $result"
}
+28
View File
@@ -0,0 +1,28 @@
// !LANGUAGE: -ProperFinally
// TARGET_BACKEND: JVM
var result = ""
fun test() {
try {
try {
result += "try"
return
} catch (fail: Throwable) {
result += " catch"
}
} finally {
result += " finally"
throw RuntimeException()
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
}
return if (result == "try finally catch finally") "OK" else "fail: $result"
}
@@ -0,0 +1,32 @@
// !LANGUAGE: +ProperFinally
var result = ""
fun test() {
try {
try {
try {
result += "try"
return
} catch (fail: Throwable) {
result += " catch"
}
} finally {
result += " finally 1"
throw RuntimeException("Fail 1")
}
} finally {
result += " finally 2"
throw RuntimeException("Fail 2")
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
if (e.message != "Fail 2") return "wrong exception: ${e.message}"
}
return if (result == "try finally 1 finally 2") "OK" else "fail: $result"
}
@@ -0,0 +1,34 @@
// !LANGUAGE: +ProperFinally
var result = ""
fun test() {
try {
try {
try {
result += "try"
return
} catch (fail: Throwable) {
result += " catch"
}
} catch (e: Throwable) {
result += " finally_catch"
} finally {
result += " finally 1"
throw RuntimeException("Fail 1")
}
} finally {
result += " finally 2"
throw RuntimeException("Fail 2")
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
if (e.message != "Fail 2") return "wrong exception: ${e.message}"
}
return if (result == "try finally 1 finally 2") "OK" else "fail: $result"
}
@@ -0,0 +1,37 @@
// !LANGUAGE: +ProperFinally
var result = ""
fun test() {
try {
try {
try {
try {
result += "try"
return
} catch (fail: Throwable) {
result += " catch"
}
} finally {
result += " finally 1"
throw RuntimeException(" exception from finally 1")
}
} catch (e: Throwable) {
result += " catch 2"
result += e.message
}
} finally {
result += " finally 2"
throw RuntimeException("Fail 2")
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
if (e.message != "Fail 2") return "wrong exception: ${e.message}"
}
return if (result == "try finally 1 catch 2 exception from finally 1 finally 2") "OK" else "fail: $result"
}
@@ -0,0 +1,36 @@
// !LANGUAGE: +ProperFinally
var result = ""
fun test() {
try {
try {
try {
try {
result += "try"
return
} catch (fail: Throwable) {
result += " catch"
}
} finally {
result += " finally 1"
}
} catch (e: Throwable) {
result += " catch 2"
result += e.message
}
} finally {
result += " finally 2"
throw RuntimeException("Fail 2")
}
}
fun box(): String {
try {
test()
return "fail: expected exception"
} catch (e: RuntimeException) {
if (e.message != "Fail 2") return "wrong exception: ${e.message}"
}
return if (result == "try finally 1 finally 2") "OK" else "fail: $result"
}