Hello! How can i force compiler to restrict 'when'...
# announcements
p
Hello! How can i force compiler to restrict 'when' expression if not all branches specified and it is not returning or assigning?
🙄 1
c
There’s no automatic way, but there is a small library available which lets you annotate when-expressions that should be exhaustive https://github.com/cashapp/exhaustive. The README also lists a few alternatives to the compiler plugin (which are probably all easier/more stable to use than the actual library) https://github.com/cashapp/exhaustive#alternatives-considered
e
for now, I find
Copy code
when (...) {
    ...
}.let { /* exhaustive */ }
to be the simplest workaround
I'd like for
val _ =
to work like I write in other languages, and I always end up trying it in Kotlin, but it doesn't work... oops
v
Just make it a face that watches you are exhaustive 🙂
Copy code
val `_` =
😑 2
😄 3
Or
Copy code
val o_O =
p
The solution with let is good for me. Thanks!