radon icon indicating copy to clipboard operation
radon copied to clipboard

[BUG]: Issue with `fallthrough` statement.

Open Almas-Ali opened this issue 1 year ago • 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

Almas-Ali avatar Apr 24 '24 12:04 Almas-Ali

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

angelcaru avatar Apr 24 '24 13:04 angelcaru

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/

Almas-Ali avatar Apr 24 '24 13:04 Almas-Ali

Yeah dude, I know how switch works. I also know how much it sucks

angelcaru avatar Apr 24 '24 13:04 angelcaru

In this case we need a new keyword fallout which will make this behavior happen. I need this anyway!

Almas-Ali avatar Apr 24 '24 13:04 Almas-Ali