google / google/xls

DSLX formatter does not provide a way to precisely comment on an else condition

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

Description

**Describe the bug**
The formatter either removes the comment or moves it inside the branch, which can be misleading.

**To Reproduce**
Steps to reproduce the behavior:
```
fn foo(x: u1) -> u32 {
if x {
u32:42
} else { // we take the else branch because
u32:0
}
}
```

is formatted to

```
fn foo(x: u1) -> u32 {
if x {
u32:42
} else {
// we take the else branch because
u32:0
}
}
```

That can be misleading as the comment is indented to match the return value here. As an attempted workaround,

```
fn foo(x: u1) -> u32 {
if x {
u32:42
}
// we take the else branch because
else {
u32:0
}
}
```
is formatted to:

```
fn foo(x: u1) -> u32 {
if x { u32:42 } else { u32:0 }
}
```

**Expected behavior**
Preserve the comment

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.