[BUG]: Issue with `fallthrough` statement.
Almas-Ali opened this issue · 4 comments
Describe the bug
Issue with fallthrough
statement in switch
statement flow.
Expected behavior
When fallthrough
statement will match, it will execute everything next to it (all cases next to it). But, now it is just executing next case only.
Screenshots or Code snippets
switch 44 {
case 42 -> print("42")
case 43 -> print("43")
case 44 -> fallthrough
case 45 -> print("45")
case 46 -> print("46")
case 47 -> print("47")
case 48 -> print("48")
default -> print("default")
}
Output:
45
Expected output:
45
46
47
48
default
This is honestly how it should work given there is no way to explicitly break out of a case
statement (as this is implied). If you wanted to print everything, just put fallthrough
in every case.
TL;DR: this is intended and part of the semantics of fallthrough
The main reason why I wanted to add fallthrough
is to make free fall behavior in switch
statement like in C, C++ or Java language.
Example: https://www.geeksforgeeks.org/fall-through-condition-in-java/
Yeah dude, I know how switch
works. I also know how much it sucks
In this case we need a new keyword fallout
which will make this behavior happen. I need this anyway!