-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
Description
On #nim the following came up: consider evaluating the following expression:
not 3 == 4
The above evaluates left-to-right as (not 3) == 4 since not and == have same precedence, although the user actually hoped for not (3 == 4) to happen.
Easily explained by pointing to the manual, but still a potential pitfall.
Modern C compilers tend to notice this and advice the user to use parenthesis. For example, clang says:
ico@platdoos:/tmp$ clang -c t.c -Wall
t.c:4:9: warning: logical not is only applied to the left hand side of this comparison
[-Wlogical-not-parentheses]
return !3 == 4;
^ ~~
t.c:4:9: note: add parentheses after the '!' to evaluate the comparison first
return !3 == 4;
^
( )
t.c:4:9: note: add parentheses around left hand side expression to silence this warning
return !3 == 4;
Is this something Nim should signal and warn about as well?
kaushalmodi