-
-
Notifications
You must be signed in to change notification settings - Fork 789
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
Warn on useless comparisons #4205
Comments
@lpil and @Papipo If we are doing this, would something like the below work? Variable:
Field access:
Would we want to implement this for anything else apart from variables and field access? |
Just field access, module selects, literal values and variables I'd say. @Ramkarthik are you planning to work on this? |
@giacomocavalieri I have implemented this for field access and variables to emit the warning mentioned in my previous comment. I can look into implementing it for module selects and literal values as well. I'll give it a try today. I'm assuming we would also want this for |
Great thank you!! Not sure we also want it for those operators, I'd just start with equality checks 👍 |
Hello! Good idea @Papipo, thank you. @Ramkarthik @giacomocavalieri The goal is to warn for useless comparisons generally, not for equality checks with the same value specifically. These should emit a warning saying they always evaluate to true: 1 < 2
3 == 3
1 != 2
1.5 >. 1.1
xyz == xyz
wibble.wobble == wibble.wobble These should emit a warning saying they always evaluate to false: 1 > 2
3 != 3
1 == 2
1.5 <. 1.1 |
@lpil Got it, that makes sense. I can work on this on the same PR (or a new one) if you'd like, or leave it open for someone/future. Would like to know your opinion on what the warning title should be. The hint can be "This is always [true | false]" depending on the condition. |
Hi there,
I had a typo in some code and I was comparing a variable with itself, like
group_id != group_id
. One of those was supposed to begroup.id
, and I think it's a common typo.The idea is that the compiler is able to detect such comparisons and warn about them, since they will always evaluate to the same and are completely useless.
Thanks 🙇🏽
The text was updated successfully, but these errors were encountered: