zig icon indicating copy to clipboard operation
zig copied to clipboard

unhelpful error message on invalid bytes inside multi line string literal

Open Techatrix opened this issue 1 year ago • 2 comments

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 avatar Aug 01 '24 16:08 Techatrix

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

jiacai2050 avatar Aug 05 '24 14:08 jiacai2050

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

Yes, see https://github.com/ziglang/zig-spec/issues/38 for details.

Vexu avatar Aug 05 '24 17:08 Vexu

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

jayschwa avatar Aug 29 '24 00:08 jayschwa

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.

sweetbbak avatar Jan 18 '25 22:01 sweetbbak