Warn if the same operand is on either side of the equality operator #4213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #4205
Based on the conversation in the comments thread of the mentioned issue, I have implemented this for variables, field access, and literals. I'm not sure about module selects. @giacomocavalieri Could you please share an example for module select? (I'm still fairly new to Gleam)
Currently, it only checks for the same operand. In the case of literals, it doesn't warn if the check is
1 == 2
(which is alwaysfalse
). Do we want to handle those cases? If yes, I will likely have to rename theWarning::EqualityOnSameOperands
variant and change the warning title. Any equality check for literals on both sides of the operator is always going to be the same result, so maybe we want to warn?This PR also doesn't handle
gt
,gte
,lt
, andlte
for Int and Float literals (based on the discussion in the issue thread).If there's a better way to phrase the warning (title, hint, etc), please let me know.
Currently, the warning message template is:
Not related: It looks like the person who added this particular changelog entry missed adding their name/link - 65d7bb5