google / google/xls

Parser should error when splat follows struct instantiation

Open
#3,019 0 comments 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**

The formatter accepts a splat `..` after a substruct member field initialization, when it is just a missing comma. It seems to treat this as a range expression, even though it doesn't make sense as a range. (I understand there may be other cases where this is ambiguous).

**To Reproduce**

```
struct Foo { a: u32, b: u32 }

struct Bar { x: u32, y: u32 }

struct Baz { foo: Foo, bar: Bar }

fn main() {
let baz = Baz{
foo: Foo { a: u32:1, b: u32:2 }
..zero!(),
};
}
```

is formatted to:

```
struct Foo { a: u32, b: u32 }

struct Bar { x: u32, y: u32 }

struct Baz { foo: Foo, bar: Bar }

fn main() { let baz = Baz { foo: Foo { a: u32:1, b: u32:2 }..zero!() }; }
}
```
**Expected behavior**

Report an error instead.

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.