-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Error/warn on switch case fallthough if there is more than one newline? #1849
Comments
Correction: More than one newline and no statements. |
Yes, I think it's reasonable, in fact this problem has actually entered my mind several times and then I consequently forgot about. There is also this example: switch (x)
{
case 0:
$if SOME_CONDITION:
foo();
$endif;
case 1:
...
} Here even the intent is unclear: did the programmer intend fallthrough if SOME_CONDITION is false – it has no statements afterwards – or what is the intention? I can somewhat lean towards treating the |
This is the downside of allowing this special case of fallthrough by the way. |
Totally agree with proposal, faced it many times when commented something inside |
So what should the exact behaviour be? One thing I could do is to require explicit break or nextcase as soon as it isn't completely empty. |
@lerno What's the reason behind implementing this as an error rather than a warning? Imagine the case : switch (myEnum) {
// Some comment explaining why it belongs to case 2
case ENUM1:
// Some comment about case2
case ENUM2:
do_something()
default:
say_hi()
} That now gives an error while I wanted that comment. |
I ran into a case recently where I had commented out the body of a switch case which made it fall through and messing up the program logic, and it took me a quite while to realize.
Would it perhaps make sense to emit an error or warning if there is more than one newline between the end of
case FOO:
andcase BAR:
?The text was updated successfully, but these errors were encountered: