Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve multiple error messages #20618

Closed
wants to merge 6 commits into from
Closed

Conversation

tau-dev
Copy link
Contributor

@tau-dev tau-dev commented Jul 13, 2024

Fixes #12547.
Fixes #12829.
Fixes #13832.
Fixes #14334.
Fixes #16019.
Fixes #16702.
Fixes #14238.

None of these are particularly related, I can pull them into separate PRs if necessary.

@tau-dev tau-dev changed the title Improve various parse error messages Improve multiple error messages Jul 13, 2024
lib/std/zig/Parse.zig Show resolved Hide resolved
lib/std/zig/AstGen.zig Outdated Show resolved Hide resolved
src/Sema.zig Outdated
=> try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}),
.Array => try sema.errNote(src_loc, msg, "packed fields are ordered according to machine endianness, array elements are not", .{}),

This comment was marked as off-topic.

Copy link
Contributor Author

@tau-dev tau-dev Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is just a note on the packed structs cannot contain fields of type '[4]u32' error message; adding "arrays are not allowed in packed structs" would be redundant.

The reason for it not being allowed, on the other hand, is rather subtle, and I think explaining it helps the user understand whether they want to solve the error by giving up packed-ness or array-ness. As far as I can tell, the reason #12547 is still open is that the status quo error message saying only "this isn't allowed" is not useful to new users.

test/compile_errors.zig Show resolved Hide resolved
@tau-dev tau-dev force-pushed the improve-parser branch 2 times, most recently from b76224d to 6624dc0 Compare July 16, 2024 21:51
tau-dev added 6 commits July 17, 2024 11:02
Fixes ziglang#14334: non-tuples are more common, and forgetting a type or name
from a struct field is an easier mistake to make than adding a name to a
tuple field.

Also addresses ziglang#18597 (the specific case presented there, but not the
general goal of that issue) by checking for mismatched parentheses after
a parser error. Unclosed parens can cause otherwise much-more-cryptic
errors.
Closes ziglang#12547: explain why arrays aren't allowed in packed structs.
Closes ziglang#13832: improve error message for a common mistake on the LHS of
the binary `!` operator.
While we can't cover every I/O function like this, lockStdErr covers
std.debug.print and std.log.*, probably the most important places to
leave a useful hint for newcomers to Zig.
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry but I do request these to be separate PRs. I went through the first 3 commits and saw things that I want to ask about in each one.

@tau-dev
Copy link
Contributor Author

tau-dev commented Jul 23, 2024

Split this into #20760, #20761, #20762, #20763 and #20764.

@tau-dev tau-dev closed this Jul 23, 2024
@tau-dev tau-dev deleted the improve-parser branch July 23, 2024 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment