google / google/xls

Last struct member on separate line autoformats with trailing comma, but struct update cannot

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

Description

**Describe the bug**
It is a parse error to have a trailing comma after a struct update `..`:

```
Expected '}', got ',': Closing brace after struct instance "splat" (..) expression.
=== Source Location Trace: === xls/dslx/frontend/bindings.h:58
```

**To Reproduce**

```
struct Point3 { x_dimension: u32, y_dimension: u32, z_dimension: u32 }

fn update_y(base_point: Point3) -> Point3[NUM_POINTS] {
for (point_idx, points): (u32, Point3[NUM_POINTS]) in range(u32:0, NUM_POINTS) {
update(
points, point_idx,
Point3 {
x_dimension: u32:123456789 + point_idx,
y_dimension: u32:987654321 + point_idx,
})
}(zero!())
}
```

Notice the trailing comma after `y_dimension`. Now try to make this a struct update based on `base_point`:

```
struct Point3 { x_dimension: u32, y_dimension: u32, z_dimension: u32 }

fn update_y(base_point: Point3) -> Point3[NUM_POINTS] {
for (point_idx, points): (u32, Point3[NUM_POINTS]) in range(u32:0, NUM_POINTS) {
update(
points, point_idx,
Point3 {
x_dimension: u32:123456789 + point_idx,
y_dimension: u32:987654321 + point_idx,
..base_point,
})
}(zero!())
}
```

You must remove the comma after `..base_point`.

**Expected behavior**
Even if default formatting is inconsistent, it doesn't seem like this should be a parse error.

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.