Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for switch-case fall-throughs without any case matching #54

Open
Tracked by #27
stv0g opened this issue Jul 31, 2023 · 1 comment
Open
Tracked by #27

Check for switch-case fall-throughs without any case matching #54

stv0g opened this issue Jul 31, 2023 · 1 comment

Comments

@stv0g
Copy link
Member

stv0g commented Jul 31, 2023

By @koraa in #27 (comment)

Severerity: N/A – What is the situation with regards to switch-case-fallthrough and none of the branches of a switch statement being covered in go?

@stv0g
Copy link
Member Author

stv0g commented Aug 1, 2023

The Go programming language does not have automatic fallthrough in switch-case statements like some other programming languages (e.g., C and C++). In Go, when a case is matched in a switch statement, it executes the corresponding block of code and then exits the switch statement.

If you want to achieve fallthrough behavior, where the execution continues to the next case block even after matching a case, you need to explicitly use the fallthrough keyword. When the fallthrough keyword is used in a case block, it forces the control flow to transfer to the next case block, regardless of whether the next case's condition is true or not.

Regarding the situation where none of the branches of a switch statement are covered, Go has strict compilation rules that require all cases to be explicitly covered. If a case is missing, the Go compiler will raise a compilation error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant