<https://github.com/JetBrains/kotlin/pull/3087> ru...
# stdlib
f
https://github.com/JetBrains/kotlin/pull/3087 running again and again into situations where I need a
when
expression to be exhaustive and it is exhaustive but the compiler cannot know, current example is
java.nio.ByteOrder
which has exactly two instances but is not defined as an enum.
r
Why not just use
error()
?
1
f
Because you always need to come up with a message. It can be used for optimizations. I allows one to find all unreachable places.
i
Because you always need to come up with a message.
Why is that a bad thing? The message could include some useful details of why that unreachable code was reached if the original assumption became false. For example it can include the actual value of argument of
when
that was expected to be exhaustive.
1
f
The Rust
unreachable
macro offers an optional message argument. We could add that too.
It could also automatically be added by the compiler. 😉