Error: value of type 'bool' ignored

I would like to share an error I got today:

ib/std/Build/Step/InstallDir.zig:246:5: error: value of type 'bool' ignored
    if (slice.len > 0 and slice[0] == value) return true else false;
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/std/Build/Step/InstallDir.zig:246:5: note: all non-void values must be used
lib/std/Build/Step/InstallDir.zig:246:5: note: this error can be suppressed by assigning the value to '_'

It was very useful, because it made me realize that the code was unnecessarily complex (and that writing code without thinking is bad).

1 Like

Hi! If the idea was to return either true or false based on the result of evaluating the condition, then you can do this:

return if (slice.len > 0 and slice[0] == value) true else false;

Or even shorter:

return slice.len > 0 and slice[0] == value;
5 Likes