mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-11 08:31:30 +00:00
Ideally, the type of `IrWhen` should be provided by type inference for a consistent behavior. `USED_AS_EXPRESSION` from CFG isn't always consistent with type inference, unfortunately. The behavior is now aligned with `if`. The type of `when` is kept when it *can* be an expression, instead of whether it is used or not.
18 lines
235 B
Kotlin
Vendored
18 lines
235 B
Kotlin
Vendored
fun test(
|
|
b: Boolean,
|
|
i: Int
|
|
) {
|
|
if (b) {
|
|
when (i) {
|
|
0 -> foo(1)
|
|
else -> null
|
|
}
|
|
} else null
|
|
}
|
|
|
|
fun foo(i: Int) = i
|
|
|
|
fun box(): String {
|
|
test(true, 1)
|
|
return "OK"
|
|
} |