ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.94k stars 2.55k forks source link

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

Open Techatrix opened 3 months ago

Techatrix commented 3 months ago

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:

Something like this:

:3:6: error: found 'invalid bytes' inside multiline string literals
:3:6: note: invalid byte: '\\x09'
jiacai2050 commented 3 months ago

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

Vexu commented 3 months ago

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.

jayschwa commented 2 months ago

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