Currently it’s not possible to emulate the fall through structure of a Java switch statement cleanly. There are example workarounds in this Stack Overflow Article, but none of them are clean, and all add levels of indirection, as well as computational overhead.
Allowing fallthrough in switch statements is a cause of bugs, and not allowing it by default in Kotlin was a good call. However, it should be possible to use fall through behavior when explicitly asked for.
This could be handled using a new keyword “fallthrough” which would be syntactically easy to read. It could also be handled through structure of curly braces, or any other mechanism.
Here is an example:
1 -> upgradeFromV1(); fallthrough
2 -> upgradeFromV2(); fallthrough
3 -> upgradeFromV3()
Is this a good idea? Is something like this possible?