-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Description
Zig Version
0.12.0-dev.3433+640acf862
Steps to Reproduce and Observed Behavior
EnumIndexer supports non-exhaustive enums, so I was expecting that EnumSet (and EnumMap) would support this too.
This can be useful to implement bitfields with sparse usage, which are common in external libraries. For example, using an enum backed by u5, the EnumSet becomes a 32-bit bitfield.
The compile error can be reproduced using this:
const std = @import("std");
const BitIndices = enum(u5) {
a = 0,
b = 1,
c = 4,
_,
};
const BitField = std.enums.EnumSet(BitIndices);
export fn example() void {
var flags = BitField.init(.{ .a = true, .b = true });
flags.insert(.c);
flags.remove(.a);
std.debug.assert(flags.contains(.b));
}Which produces an error from EnumSet.init as follows:
/opt/compiler-explorer/zig-master/lib/std/enums.zig:268:29: error: no field with value '@enumFromInt(2)' in enum 'BitIndices'
Expected Behavior
Successful compile and test.
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior