google / google/xls

[DSLX] In struct parametrics `as` is not constexpr-compatible

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

Description

**Describe the bug**

Try to build this:

```
pub struct foo {
data: xN[IS_SIGNED as u1][NUM_BITS],
}

#[test]
fn test_instantiate_foo() {
let _ = foo { data: u1:0};
}
```

observe error:
```
Could not evaluate dimension expression `IS_SIGNED as u1` to a constant value.
```

**To Reproduce**
Use code above, try to compile.

**Expected behavior**
I expect that I can cast a `u32` to a `u1` to define a type. That is, I expect that casting is constexpr-compatible.

**More comments**
I tried another way of accomplishing the same thing:
```
pub struct foo u32:0} > {
data: xN[sign][NUM_BITS],
}

#[test]
fn test_instantiate_foo() {
let _ = foo { data: u1:0};
}
```
and when I try to build and test:
```
Error: INVALID_ARGUMENT: Cannot convert expression to parametric: IS_SIGNED > u32:0
```

let's try again, but same error (i.e., Cannot convert expression to parametric):
```
pub struct foo u32:0 {true}else{false}} > {
data: xN[sign][NUM_BITS],
}
```

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.