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

Formatter crashes when there are comments in array literals #1885

Open
dank-openai opened this issue Jan 24, 2025 · 1 comment
Open

Formatter crashes when there are comments in array literals #1885

dank-openai opened this issue Jan 24, 2025 · 1 comment
Labels
dslx:fmt DSLX auto-formatter dslx DSLX (domain specific language) implementation / front-end

Comments

@dank-openai
Copy link

Describe the bug

If one has a comment, on its own line, inside an array literal, the formatter crashes. I suspect

E0124 16:38:30.802721 22622349 json-rpc-dispatcher.cc:104] Method error for 'textDocument/formatting' :absl::container_internal::raw_hash_map<>::at
[Error - 4:38:30 PM] Request textDocument/formatting failed.
  Message: absl::container_internal::raw_hash_map<>::at
  Code: -32603 

To Reproduce

pub const TABLE = [
    //break formatter
(u32:0, u32:0), (u32:0, u32:0), (u32:0, u32:0), (u32:0, u32:0), (u32:0, u32:0), (u32:0, u32:0),
(u32:0, u32:0),
];

Run the formatter.

Expected behavior

It should certainly not crash. In the short term, maybe it should ignore (not format) this particular syntactical block, and format the rest of the file.
Not to be prescriptive about how to format... but since you asked: It should format like this, or similar. It should probably align the comment with the other array elements. It should format the non-comments as if the comment didn't exist (but put the comment back where it belongs):

pub const TABLE = [
    //break formatter
    (u32:0, u32:0), (u32:0, u32:0), (u32:0, u32:0), (u32:0, u32:0), (u32:0, u32:0), (u32:0, u32:0),
    (u32:0, u32:0),
];
@cdleary cdleary added the dslx:fmt DSLX auto-formatter label Jan 27, 2025
@dplassgit
Copy link
Collaborator

In this case it refuses to format that expression because it knows it would lose the comment. It comes out as a crash, but the error message is something like:

INTERNAL: Formatting was skipped because a comment at [location] would be deleted by the formatter: //break formatter
This is probably due to a bug (which may not have been reported yet). To complete formatting, try moving the comment to a different line.

@dplassgit dplassgit added the dslx DSLX (domain specific language) implementation / front-end label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dslx:fmt DSLX auto-formatter dslx DSLX (domain specific language) implementation / front-end
Projects
Status: No status
Development

No branches or pull requests

3 participants