Can I test for `when` exhaustiveness without assig...
# compiler
r
Can I test for
when
exhaustiveness without assigning the result to a variable?
val x: Unit =
feels a bit silly.
I think you should be able to use it already with progressive mode (https://kotlinlang.org/docs/whatsnew13.html#progressive-mode) but I haven’t tried it myself
Alternatively, as a quick workaround, you can define an extension function or property
exhaustive
that, when called on the
when
result, will force exhaustiveness. Another way is what I use often, to have the
when
a result of an expression function — it very often makes sense anyway
e
the built-in exhaustive mode is already default in Kotlin 1.7
my preference for a workaround in earlier versions or in cases where the built-in exhaustiveness checker isn't enabled by default is a trailing
Copy code
when {
    ...
}.let { /* exhaustive */ }
which has no extra impact
j
@ephemient is possible disable exhaustive in kotlin 1.7?
e
with
-language-version 1.5
it should not be enabled