google / google/xls

[DSLX] can't use parametric constexprs in struct definition

Open
#1,867 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**

I'm unable to do something with parametrics; I think it should be legal. As best as I can tell, the narrowest definition of the bug is: I can't use constexprs in a struct's parametric definitions.

**To Reproduce**

```
pub struct FixedPoint u32:0} > {
data: xN[SIGNED_BOOL][NUM_BITS],
}

#[test]
fn test_instantiate_FixedPoint() {
let a = FixedPoint { data: u5:1};
assert_eq(a.data, u5:1);
}
```

Build and _test_ the above. The error shows up during the test.

```
Error: INVALID_ARGUMENT: Cannot convert expression to parametric: SIGNED > u32:0================================================================================
```

**Expected behavior**
It should work, the test should pass.

**Additional context**

If you're wondering why I made SIGNED a u32 instead of bool, see [this bug.](https://github.com/google/xls/issues/1841)

I find it strange that this error appears at test runtime instead of typechecking.

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.