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

fix: Correct error message for invalid bytes in multiline strings #21459

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WillLillis
Copy link
Contributor

@WillLillis WillLillis commented Sep 20, 2024

This change provides a correct error message when an invalid byte is found inside of a multiline string line. Taking the example from #20900:

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

Before:

src/main.zig:4:1: error: expected ';' after statement
    \\ // hello
^

After:

src/main.zig:4:5: error: expected 'a string literal', found invalid bytes
    \\ // hello
    ^~~~~~~~~~~
src/main.zig:4:7: note: invalid byte: '\t'
    \\ // hello
      ^~~~~~~~~~~

I'm not 100% confident in the set of invalid bytes I added in lowerAstErrors, as it's just based off of those listed in the multiline_string_literal_line case of Tokenizer.next(). I think this part of the PR in particular could benefit from a close second check. :)

I initially thought that the similar problem with invalid bytes inside comments (mentioned here), but there isn't a .comment variant (only .doc_comment and .container_doc_comment) of Token.Tag to report the expected token as. Another variant to Ast.Error.Tag could be added to handle this case, but I wanted to check before doing so.

One minor nit/ bikeshed question: The rendered error message for this case reads error: expected 'a string literal', found invalid bytes. Since this error is triggered by the first single invalid byte encountered by the tokenizer, should this message use "byte" instead?

Closes #20900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unhelpful error message on invalid bytes inside multi line string literal
1 participant