Skip to content

Unintuitive error for omitting field type in struct #23045

@kiedtl

Description

@kiedtl

Zig Version

0.14.0-dev.3446+50b40c962

Steps to Reproduce and Observed Output

const S = struct { a: usize = 1, b = 2, c: isize = 3, d: []const u8 };

yields

test.zig:1:20: error: tuple field has a name
const S = struct { a: usize = 1, b = 2, c: isize = 3, d: []const u8 };

Expected Output

This is an extremely confusing error message, particularly so as the error points to the first field rather than the offending one. In a large struct (where I encountered this error), the field with a missing type was 30-something lines down.

As suggested in Discord, the compiler could output a note: "note: struct is a tuple due to this unnamed field".

Personally, I would prefer the error message be changed. I'm not familiar with the compiler internals, though, so I don't know which would be easier or require a refactor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions