-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Missing compiler warning on if-clause #5109
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
Comments
While I am dubious of any actual use case for that sort of code, a good workaround for now is to use TSLint: https://github.com/palantir/tslint The |
Thanks for your reply. Indeed this type of code should not be used, it was just a mistake and I wondered why the if path got hit independent of the value of x... (I think you how easy it is to overread such a little mistake while debugging ;-) ). |
I'm not aware of any C-syntax languages that flag this as an error. +1 for TSLint. I remember spending a long time in college debugging this infinite loop 😝 int x = 0;
while (x < 10); {
x++;
} |
i do think there is room for making this an error. it is clearly wrong, or at best very bad pattern to follow, in the case of the if statement, and can be detected in cases of while/for cases if we limit it to expressions with side-effects (let's say only assignments, and call expressions). |
Yes, I somewhat agree; unlike a |
Accepting PRs. The only rule we want is that the "true" arm of an |
thanks @MartyIX! |
Hi,
last week I made a mistake while typing an if-clause:
if(x === false);
{...}
When I debugged it, the code inside the brackets got hit every time. For many code runs I did not see the wrong semicolon after the if-statement.
For me, a compiler warning about the misplaced semicolon would be great, like the C# compiler does it.
Helmut
The text was updated successfully, but these errors were encountered: