zig icon indicating copy to clipboard operation
zig copied to clipboard

Missing compile error for `enum(u0){a,_}`

Open rohlem opened this issue 1 year ago • 0 comments

Zig Version

0.13.0-dev.46+3648d7df1, 0.12.0-dev.3182+f3227598e

Steps to Reproduce and Observed Behavior

The compiler currently errors when an enum is declared as non-exhaustive (with pseudo-member _) while specifying every possible value as state. However, this error doesn't trigger when the backing type is a zero-bit type (u0 or i0):

comptime {
    _ = enum(u0) { a, _ };
    _ = enum(u1) { a, b, _ };
}
main.zig:3:9: error: non-exhaustive enum specifies every value
    _ = enum(u1) { a, b, _ };
        ^~~~~~~~~~~~~~~~~~~~

Expected Behavior

main.zig:2:9: error: non-exhaustive enum specifies every value
    _ = enum(u0) { a, _ };
        ^~~~~~~~~~~~~~~~~

Note that the same error is present for instantiation via @Type; I assume the compiler-internal code for both places is shared, so that a fix would apply to both scenarios.

rohlem avatar May 04 '24 07:05 rohlem