A small nitpicking inconsistency in Zig


    // The two are less consistent.
    const v = T{.x = 1, .y = true}; // why not T.{.x = 1, .y = true} ?
    const v: T = .{.x = 1, .y = true};
    
    // The two are more consistent.
    const v = T.declOrTag;
    const v: T = .declOrTag;

My understanding:

This is assigning a T struct to v.

const v = T{.x = 1, .y = true};

This is an anonymous struct being assigned to v, which gets coerced to a T.

const v: T = .{.x = 1, .y = true};

So it wouldn’t really make sense to have T.{.x = 1, .y = true}

1 Like

The dot is a stand-in for the type. It’s <thing>{ .x = 1 }, and <thing> can be either a type name, or a dot.