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

unhelpful error message on invalid bytes inside multi line string literal #20900

Closed
Techatrix opened this issue Aug 1, 2024 · 4 comments · Fixed by #21459
Closed

unhelpful error message on invalid bytes inside multi line string literal #20900

Techatrix opened this issue Aug 1, 2024 · 4 comments · Fixed by #21459
Labels
error message This issue points out an error message that is unhelpful and should be improved. regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@Techatrix
Copy link
Contributor

Techatrix commented Aug 1, 2024

Zig Version

0.14.0-dev.764+eb1a199df

Steps to Reproduce and Observed Output

// example.zig
const foo =
    \\const S = struct {
    \\<TAB>// hello
    \\}
;

Running zig fmt --check example.zig outputs:

example.zig:3:1: error: expected ';' after declaration
    \\ // hello
^

This message had me so confused that I though that there was a bug in the parser or tokenizer. Luckily it was just #20885 rejecting tabs inside multiline string literals.

Expected Output

I would expect an error message that does fulfills these requirements:

  • mention that invalid bytes have been encountered
  • mention where the invalid byte is located
  • mention the value of the byte

Something like this:

:3:6: error: found 'invalid bytes' inside multiline string literals
:3:6: note: invalid byte: '\\x09'
@Techatrix Techatrix added the error message This issue points out an error message that is unhelpful and should be improved. label Aug 1, 2024
@Vexu Vexu added the regression It worked in a previous version of Zig, but stopped working. label Aug 1, 2024
@Vexu Vexu added this to the 0.14.0 milestone Aug 1, 2024
@jiacai2050
Copy link
Contributor

This bug also bite me, does this mean we are not allowed to use tab in multi line string?

@Vexu
Copy link
Member

Vexu commented Aug 5, 2024

does this mean we are not allowed to use tab in multi line string?

Yes, see ziglang/zig-spec#38 for details.

@jayschwa
Copy link
Contributor

The unhelpful error also occurs when a comment has an invalid byte.

@sweetbbak
Copy link
Contributor

I just spent longer than I want to admit tracking down a bug that ended up being a tab in a comment... I feel like this is an error that zig fmt could have easily fixed, but it currently doesn't.

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. regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants