Fixed bug in <when> codegen + test
This commit is contained in:
+2
@@ -2449,6 +2449,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
functionGenerationContext.assignPhis(resultPhi to brResult)
|
functionGenerationContext.assignPhis(resultPhi to brResult)
|
||||||
if (bbExit != null)
|
if (bbExit != null)
|
||||||
functionGenerationContext.br(bbExit)
|
functionGenerationContext.br(bbExit)
|
||||||
|
else
|
||||||
|
functionGenerationContext.unreachable()
|
||||||
}
|
}
|
||||||
if (bbNext != null) // Switch generation to next or exit.
|
if (bbNext != null) // Switch generation to next or exit.
|
||||||
functionGenerationContext.positionAtEnd(bbNext)
|
functionGenerationContext.positionAtEnd(bbNext)
|
||||||
|
|||||||
@@ -1370,6 +1370,11 @@ task advanced_when5(type: RunKonanTest) {
|
|||||||
source = "codegen/branching/advanced_when5.kt"
|
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) {
|
task bool_yes(type: RunKonanTest) {
|
||||||
source = "codegen/function/boolean.kt"
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user