Split exception table on finally insertion before non-local return
in nested try blocks without finally #KT-31653 Fixed
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
// !LANGUAGE: +ProperFinally
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
var result = ""
|
||||
|
||||
inline fun a(f: () -> Any) =
|
||||
try {
|
||||
f()
|
||||
} finally {
|
||||
throw RuntimeException()
|
||||
}
|
||||
|
||||
fun b(vararg functions: () -> Any) = a {
|
||||
for (function in functions) {
|
||||
try {
|
||||
return function()
|
||||
} catch (fail: Throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
b({ result += "OK"; 1 }, { result += "fail"; 2 })
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
// NO_CHECK_LAMBDA_INLINING
|
||||
import test.*
|
||||
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
b({ result += "OK"; 1 }, { result += "fail"; 2 })
|
||||
return "fail: expected exception"
|
||||
} catch (e: RuntimeException) {
|
||||
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// !LANGUAGE: +ProperFinally
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
var result = ""
|
||||
|
||||
class A {
|
||||
var field = 0
|
||||
inline fun a(f: () -> Any): Any {
|
||||
try {
|
||||
val value = f()
|
||||
return value
|
||||
} finally {
|
||||
field--
|
||||
}
|
||||
}
|
||||
fun c(vararg functions: () -> Any): Any = a {
|
||||
for (function in functions) {
|
||||
try { return function() } catch (fail: Throwable) { }
|
||||
}
|
||||
throw RuntimeException()
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
// NO_CHECK_LAMBDA_INLINING
|
||||
import test.*
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
a.c({ result += "OK"; 1 }, { result += "fail"; 2 })
|
||||
if (a.field != -1) return "fail: -1 != ${a.field}"
|
||||
|
||||
return result
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// !LANGUAGE: +ProperFinally
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
var result = ""
|
||||
|
||||
inline fun inlineFun(block: (String)-> String) {
|
||||
try {
|
||||
try {
|
||||
result += block("lambda")
|
||||
return
|
||||
} catch (fail: Throwable) {
|
||||
result += " catch"
|
||||
}
|
||||
} finally {
|
||||
result += " finally"
|
||||
throw RuntimeException()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun test() {
|
||||
inlineFun {
|
||||
result += it
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
test()
|
||||
return "fail: expected exception"
|
||||
} catch (e: RuntimeException) {
|
||||
|
||||
}
|
||||
|
||||
return if (result == "lambda finally") "OK" else "fail: $result"
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// !LANGUAGE: +ProperFinally
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
var result = ""
|
||||
|
||||
inline fun inlineFun(block: (String)-> String) {
|
||||
try {
|
||||
try {
|
||||
result += block("lambda")
|
||||
} catch (fail: Throwable) {
|
||||
result += " catch"
|
||||
}
|
||||
} finally {
|
||||
result += " finally"
|
||||
throw RuntimeException()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun test() {
|
||||
inlineFun {
|
||||
result += it
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
test()
|
||||
return "fail: expected exception"
|
||||
} catch (e: RuntimeException) {
|
||||
|
||||
}
|
||||
|
||||
return if (result == "lambda finally") "OK" else "fail: $result"
|
||||
}
|
||||
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
// !LANGUAGE: -ProperFinally
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
var result = ""
|
||||
|
||||
inline fun inlineFun(block: (String)-> String) {
|
||||
try {
|
||||
try {
|
||||
result += block("lambda")
|
||||
return
|
||||
} catch (fail: Throwable) {
|
||||
result += " catch"
|
||||
}
|
||||
} finally {
|
||||
result += " finally"
|
||||
throw RuntimeException()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun test() {
|
||||
inlineFun {
|
||||
result += it
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
test()
|
||||
return "fail: expected exception"
|
||||
} catch (e: RuntimeException) {
|
||||
|
||||
}
|
||||
|
||||
return if (result == "lambda finally catch finally") "OK" else "fail: $result"
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
|
||||
// !LANGUAGE: +ProperFinally
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
|
||||
Reference in New Issue
Block a user