bad_bit_mask
Finds a mask test that can never match ((x & 4) == 1, (x | 2) == 0).
Category correctness, deny by default.
#import "Basic";
can_write :: (flags: u32) -> bool {
return (flags & 4) == 1;
}
main :: () {
print("%\n", can_write(5));
}error[bad_bit_mask]: `(flags & 4) == 1` is always `false`: `& 4` leaves only the bits of 4, and 1 has others
--> example.jai:4:13
|
4 | return (flags & 4) == 1;
| ^^^^^^^^^^^^^^^
|
help: compare with the mask itself (`(x & m) == m`) or test for non-zero
|
4 ~ return false;
|
= note: `bad_bit_mask` is `deny` by default#import "Basic";
can_write :: (flags: u32) -> bool {
return (flags & 4) != 0;
}
main :: () {
print("%\n", can_write(5));
}x & m has only bits of m, so a constant with a bit outside m is never equal to it; x | m always has the bits of m, so a constant missing one never equals it.