zig icon indicating copy to clipboard operation
zig copied to clipboard

Incorrect error message when assigning to a field in a struct definition

Open ehaas opened this issue 2 years ago • 2 comments

Zig Version

0.11.0-dev.3395+1e7dcaa3a

Steps to Reproduce and Observed Output

const S = struct {
    foo: u32,
    bar: u32,
    baz = 5,
};

Output:

~ % zig build-obj test.zig
test.zig:2:5: error: tuple field has a name
    foo: u32,
    ^~~

Expected Output

Caret should point to baz and the message should be more clear (if the foo and bar fields aren't present, the error message is use of undeclared identifier 'baz')

ehaas avatar Jun 13 '23 16:06 ehaas

personally i would assume the error message to be that you're missing const or var on baz

nektro avatar Jun 13 '23 16:06 nektro

That would work too - if we put a semicolon instead of a comma after baz the error is:

test.zig:4:12: error: expected ',' after field
    baz = 5;
           ^
test.zig:4:5: note: use 'var' or 'const' to declare variable
    baz = 5;
    ^~~

ehaas avatar Jun 13 '23 17:06 ehaas

Duplicate of #14334.

tau-dev avatar Jul 10 '24 19:07 tau-dev