zig icon indicating copy to clipboard operation
zig copied to clipboard

std.enums.EnumFieldStruct can't accept `null` as default value

Open Jack-Ji opened this issue 9 months ago • 2 comments

Zig Version

0.13.0-dev.211+6a65561e3

Steps to Reproduce and Observed Behavior

const std = @import("std");

const E = enum {
    a,
    b,
};

const ES = std.enums.EnumFieldStruct(E, ?u8, null);

pub fn main() void {
    const e = ES{ .a = 0 };
    _ = e;
}

zig build-exe gives:

enum_field_struct.zig:11:17: error: missing struct field: b
    const e = ES{ .a = 0 };
              ~~^~~~~~~~~~
.zvm/master/lib/std/enums.zig:27:12: note: struct 'enums.EnumFieldStruct(enum_field_struct.E,?u8,null)' declared here
    return @Type(.{ .Struct = .{
           ^~~~~
referenced by:
    callMain: .zvm/master/lib/std/start.zig:514:17
    callMainWithArgs: .zvm/master/lib/std/start.zig:482:12
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Expected Behavior

Compile successfully.

Jack-Ji avatar May 18 '24 13:05 Jack-Ji