Skip to content

improve invalid tuple errors#23049

Open
xdBronch wants to merge 1 commit intoziglang:masterfrom
xdBronch:push-nvsqpktymnon
Open

improve invalid tuple errors#23049
xdBronch wants to merge 1 commit intoziglang:masterfrom
xdBronch:push-nvsqpktymnon

Conversation

@xdBronch
Copy link
Copy Markdown
Contributor

@xdBronch xdBronch commented Mar 3, 2025

this does 2 things

  1. add a note when a tuple field has a name, fixes Unintuitive error for omitting field type in struct #23045
    before:
a.zig:1:20: error: tuple field has a name
const S = struct { a: usize = 1, b = 2, c: isize = 3, d: []const u8 };
                   ^

after:

a.zig:1:20: error: tuple field has a name
const S = struct { a: usize = 1, b = 2, c: isize = 3, d: []const u8 };
                   ^
a.zig:1:34: note: tuple field here
const S = struct { a: usize = 1, b = 2, c: isize = 3, d: []const u8 };
                                 ^~~~~
  1. fix the note when a decl is encountered in a tuple but the first field also has a name
const S2 = struct {
    const a = 0;
    b: u8 = 0,
    u8,
};

before:

a.zig:2:5: error: tuple declarations cannot contain declarations
    const a = 0;
    ^~~~~~~~~~~
a.zig:3:5: note: tuple field here
    b: u8 = 0,
    ^~~~~~~~~

after:

a.zig:2:5: error: tuple declarations cannot contain declarations
    const a = 0;
    ^~~~~~~~~~~
a.zig:4:5: note: tuple field here
    u8,
    ^~

@rohlem
Copy link
Copy Markdown
Contributor

rohlem commented Mar 3, 2025

seems to be an alternative to #20762
(I personally prefer the other PR, because struct types are more common in my experience, therefore it makes sense to treat them as the default.
Having a note point at the tuple field is a handy addition though, maybe we could have both?)

@xdBronch
Copy link
Copy Markdown
Contributor Author

xdBronch commented Mar 3, 2025

thanks, yeah i probably would prefer what the other pr is doing there, i just did the simplest fix rather than changing the error. i do believe that pr will need to be redone since tuples have been reworked though, not sure how much more difficult it might be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unintuitive error for omitting field type in struct

2 participants