Fixed bug in finally blocks lowering + test

Return type must be taken from the function
This commit is contained in:
Igor Chevdar
2018-06-29 12:21:08 +03:00
parent 6a07322f62
commit 11c4a2518d
3 changed files with 43 additions and 4 deletions
+5
View File
@@ -1893,6 +1893,11 @@ task finally11(type: RunKonanTest) {
source = "codegen/try/finally11.kt"
}
task finally_returnsDifferentTypes(type: RunKonanTest) {
goldValue = "zzz\n42\n"
source = "codegen/try/returnsDifferentTypes.kt"
}
task scope1(type: RunKonanTest) {
goldValue = "1\n"
source = "codegen/dataflow/scope1.kt"
@@ -0,0 +1,28 @@
package codegen.`try`.returnsDifferentTypes
import kotlin.test.*
class ReceiveChannel<out E>
inline fun <E, R> ReceiveChannel<E>.consume(block: ReceiveChannel<E>.() -> R): R {
try {
return block()
}
finally {
println("zzz")
}
}
inline fun <E> ReceiveChannel<E>.elementAtOrElse(index: Int, defaultValue: (Int) -> E): E =
consume {
if (index < 0)
return defaultValue(index)
return 42 as E
}
fun <E> ReceiveChannel<E>.elementAt(index: Int): E =
elementAtOrElse(index) { throw IndexOutOfBoundsException("qxx") }
@Test fun runTest() {
println(ReceiveChannel<Int>().elementAt(0))
}