Remove external finally block interval on splitting during inline

#KT-20433 Fixed
This commit is contained in:
Mikhael Bogdanov
2017-11-03 14:08:10 +01:00
parent f51709e61c
commit 800cc63347
12 changed files with 330 additions and 4 deletions
@@ -0,0 +1,47 @@
// FILE: 1.kt
//WITH_RUNTIME
package test
public inline fun <T, R> T.mylet(block: (T) -> R): R {
return block(this)
}
// FILE: 2.kt
import test.*
var message = ""
fun foo(root: String): String {
try {
return root.let { _ ->
try {
if (!random()) {
return root
}
return "fail $root"
} catch (e: Exception) {
message += "${e.message} "
}
"fail"
}
} finally {
message += "Finally block"
}
}
var exception = false
fun random() = if (exception) error("Exception") else false
fun box(): String {
var okResult = foo("OK")
if (okResult != "OK") return "fail 1: $okResult"
if (message != "Finally block") return "fail 2: $message"
message = ""
exception = true
if (foo("OK") != "fail") return "fail 3: ${foo("OK")}"
if (message != "Exception Finally block" ) return "fail 4: $message"
return okResult
}
@@ -0,0 +1,47 @@
// FILE: 1.kt
//WITH_RUNTIME
package test
public inline fun <T, R> T.mylet(block: (T) -> R): R {
return block(this)
}
// FILE: 2.kt
import test.*
var message = ""
fun foo(root: String): String {
try {
return root.let { _ ->
try {
if (!random()) {
return root
}
return "fail $root"
} catch (e: Exception) {
message += "Exception $e"
}
"fail"
}
} finally {
message += "Finally block"
}
}
var fail = false
fun random() = fail
fun box(): String {
var okResult = foo("OK")
if (okResult != "OK") return "fail 1: $okResult"
if (message != "Finally block") return "fail 2: $message"
message = ""
fail = true
if (foo("OK") != "fail OK") return "fail 3: ${foo("OK")}"
if (message != "Finally block" ) return "fail 4: $message"
return okResult
}
@@ -0,0 +1,47 @@
// FILE: 1.kt
//WITH_RUNTIME
package test
public inline fun <T, R> T.mylet(block: (T) -> R): R {
return block(this)
}
// FILE: 2.kt
import test.*
var message = ""
fun foo(root: String) {
try {
return root.let { _ ->
try {
if (!random()) {
message += root
return
}
message += "fail $root"
} catch (e: Exception) {
message += "Exception $e"
}
"fail"
}
} finally {
message += " Finally block"
}
}
var fail = false
fun random() = fail
fun box(): String {
foo("OK")
if (message != "OK Finally block") return "fail 1: $message"
message = ""
fail = true
foo("OK")
if (message != "fail OK Finally block" ) return "fail 2: $message"
return "OK"
}
@@ -0,0 +1,48 @@
// FILE: 1.kt
//WITH_RUNTIME
package test
public inline fun <T, R> T.mylet(block: (T) -> R): R {
return block(this)
}
// FILE: 2.kt
import test.*
var message = ""
fun foo(root: String) {
try {
root.let { _ ->
try {
if (!random()) {
message += root
return
}
message += "fail $root"
return
} catch (e: Exception) {
message += "${e.message}"
}
"fail"
}
} finally {
message += " Finally block"
}
}
var exception = false
fun random() = if (exception) error("Exception") else false
fun box(): String {
foo("OK")
if (message != "OK Finally block") return "fail 1: $message"
message = ""
exception = true
foo("OK")
if (message != "Exception Finally block" ) return "fail 2: $message"
return "OK"
}