``` private fun whenTest(a: Boolean, b: Boolean) =...
# announcements
d
Copy code
private fun whenTest(a: Boolean, b: Boolean) = when {
    a && b -> ""
    !a && b -> ""
    a && !b -> ""
    !a && !b -> ""
}
i'm being told this when expression isn't exhaustive, and that it needs an
else
is this a bug?
e
Maybe the
or
cases?
d
this is an exhaustive truth table, no matter what other ways of checking the variables you introduce, it will be covered by one of these checks
p
just use
else ->
instead of
!a && !b ->
🙂
d
i know i can do that, but the compiler is lying
e
Ah I think I know what’s going on. It asks for a
else
because there is no bound for
when
, sth like
when (someEnum) { ... }
. So the condition branches can be any statement that results in a
Boolean
. Even though you’re branches covers all possibilities for
a
and
b
, there is still infinite possibilities out there that does not involve `a`/`b`.
d
fair point
e
Technically it is not a bug, but maybe some room for improvement.
âž• 1
d
i created an issue for it (a feature request), but it turns out it's already registered as a bug: https://youtrack.jetbrains.net/issue/KT-20943