-
Notifications
You must be signed in to change notification settings - Fork 24
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
bool comparison false positive #53
Comments
I think that would make it obvious that the value might not be a boolean whereas |
One is more explicit the other more concise, I guess my main concern is that |
would you have a few examples of this scenario? perhaps there are some heuristics to determine and avoid such cases. |
@nerdypepper For a snippet like this: let
f = value:
if <condition>
then <first branch>
else <second branch>;
in
f <argument> The below is a table that shows the evaluation result when
[W01] Warning: Unnecessary comparison with boolean
╭─[default.nix:3:8]
│
3 │ if value == true
· ──────┬──────
· ╰──────── Comparing value with boolean literal true
───╯ The warning message suggests that |
This is a function that I use: let
# Imply that `cond` is not falsy, if it is,
# return `default` and otherwise `val`.
imply = cond: val: implyDefault cond null val;
implyDefault = cond: default: val:
if (cond == null) || cond == false || cond == { } || cond == [ ] || cond == ""
|| cond == 0 then
default
else
val;
in Statiz wants to change |
There are cases where we may want to test a value that may or may not be a boolean like so
if v == true
. Statix currently suggests I reduce this toif v
.If I do the reduction, and
v
is not a boolean, evaluation aborts with a type mismatch error. I could change it toif builtins.isBool v && v
, butif v == true
seems more concise in that case.The text was updated successfully, but these errors were encountered: