Fixed bug in <when> codegen + test

This commit is contained in:
Igor Chevdar
2018-05-21 13:44:42 +03:00
parent b218a3a7a2
commit 74e1783e2b
3 changed files with 29 additions and 0 deletions
@@ -2449,6 +2449,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
functionGenerationContext.assignPhis(resultPhi to brResult)
if (bbExit != null)
functionGenerationContext.br(bbExit)
else
functionGenerationContext.unreachable()
}
if (bbNext != null) // Switch generation to next or exit.
functionGenerationContext.positionAtEnd(bbNext)
+5
View File
@@ -1370,6 +1370,11 @@ task advanced_when5(type: RunKonanTest) {
source = "codegen/branching/advanced_when5.kt"
}
task when_with_try1(type: RunKonanTest) {
goldValue = "null\nnull\n42\n"
source = "codegen/branching/when_with_try1.kt"
}
task bool_yes(type: RunKonanTest) {
source = "codegen/function/boolean.kt"
}
@@ -0,0 +1,22 @@
package codegen.branching.when_with_try1
import kotlin.test.*
@Test fun runTest() {
println(foo(Any()))
println(foo("zzz"))
println(foo("42"))
}
fun foo(value: Any): Int? {
if (value is CharSequence) {
try {
return value.toString().toInt()
} catch (e: NumberFormatException) {
return null
}
}
else {
return null
}
}