Skip to content

Canonicalize identifiers in error messages #16702

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

Open
mk12 opened this issue Aug 5, 2023 · 2 comments · May be fixed by #20761
Open

Canonicalize identifiers in error messages #16702

mk12 opened this issue Aug 5, 2023 · 2 comments · May be fixed by #20761
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@mk12
Copy link
Contributor

mk12 commented Aug 5, 2023

Zig Version

0.12.0-dev.5+fc6e57568

Steps to Reproduce and Observed Output

$ echo 'const x = @"a\nb";' > test.zig
$ zig build-exe test.zig
test.zig:1:11: error: use of undeclared identifier 'a
                      b'
const x = @"a\nb";
          ^~~~~~~

Expected Output

I'd prefer if the error message represented the identifier the same way it looks in Zig source:

test.zig:1:11: error: use of undeclared identifier @"a\nb"
const x = @"a\nb";
          ^~~~~~~

In other words, print identifiers the same way zig fmt would canonicalize them (#166). And if that requires @"...", then don't bother adding single quotes around it.

@mk12 mk12 added the error message This issue points out an error message that is unhelpful and should be improved. label Aug 5, 2023
@travisstaloch
Copy link
Contributor

Not sure where it would need to be applied, but it seems like changing the error printing code to something like the following would work.

try writer.print("{}", .{std.zig.fmtEscapes(identifier_name)});

@mk12
Copy link
Contributor Author

mk12 commented Aug 8, 2023

Another place this code be done is in the {any} formatting. Maybe I should open another issue for that.

@Vexu Vexu added this to the 1.0.0 milestone Aug 8, 2023
tau-dev added a commit to tau-dev/zig that referenced this issue Jul 13, 2024
tau-dev added a commit to tau-dev/zig that referenced this issue Jul 16, 2024
tau-dev added a commit to tau-dev/zig that referenced this issue Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
3 participants