would it be possible for the compiler to detect th...
# language-proposals
l
would it be possible for the compiler to detect that
else
is not needed here? right now i HAVE to put an
else
, otherwise it wont compile
a
can you motivate it somehow better? 😄 I think currently you should get a suggestion in the IDE to simplify it to
val x = 42
l
Untitled
âž• 1
g
I'm not understanding. If you know only 1 branch can happen, why have when? Insted of just the code for that 1 branch.
l
assume the conditions arent known at compile time. i just hardcoded them to keep the example short
g
but then the
else
is needed?
l
no its not. there is only 4 possible outcomes since the conditions are immutable
c
AFAIK exhaustive whens are reserved for sealed classes and enums. Of course you are covering all permutations with the booleans I'm unsure how high of a priority this would be for Kotlin. Getting further into the language you have better ways to represent information instead of just
true
and
false
. Christina Lee's talk on representing state is an excellent watch to get a better idea about why there is probably a better option than a primative boolean.

https://www.youtube.com/watch?v=-lVVfxsRjcYâ–¾