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
@@ -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
}
}