google / google/xls

Formatter crashes when there are comments in array literals

Open
#1,885 2 comments 0 reactions 0 assignees View on GitHub
dslx dslx:fmt
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

**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),
];
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.