Ticket #50 (new enhancement)
Warn about comparisons to the same variable
Reported by: | Chuck | Owned by: | |
---|---|---|---|
Priority: | medium | Milestone: | |
Component: | Cobra Compiler | Version: | 0.8.0 |
Keywords: | warning, comparison | Cc: |
Description
Comparisons to the same variable should cause a warning:
if x == x if x == +x if x > x*1
- It could be any of the comparison operators
- The compiler should not be confused by identity operations such as +0, *1 and unary plus (+x); or by syntactic cruft like extra parenthesis.
The warning should read:
A comparison made to same variable. Did you mean to compare something else?
It might be desireable to extend this to properties, if we reach a decision that the Cobra compiler can assume that properties do not have side effects and that multiple threads are not allowed to mutate an object in parallel. If that assumption is too strong, we might consider a compiler flag for it.
if x.name == x.name ...
Change History
Note: See
TracTickets for help on using
tickets.