Fixed bug in finally blocks lowering + test
Return type must be taken from the function
This commit is contained in:
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user