&, |, ^, ~, << and >> (and their &=-style assignments) work on the bits of a plain
int. A unit of measure describes a quantity, and its bits mean nothing on their own: masking a
length in metres or shifting a duration is almost certainly a bug. Strip the unit with int(x)
when the bit pattern really is what you want.
Wrong#
fn flags(n: int<B>): int = n & 0xffFixed#
fn flags(n: int<B>): int = int(n) & 0xffCommon causes#
- A byte count or ID carrying a unit used as a bit field: convert it with
int(x)first. - Scaling by a power of two with
<<: multiply instead (n * 4), which keeps the unit.