google / google/xls

bad type inference for range expression

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

Description

**Describe the bug**

It seems that range expression don't type-coerce into properly annotated typed array but instead redefine the type binding to be the max size of the range.

**To Reproduce**

```
#[test]
fn test_array2d_tiv2() {
let data: u32[8][2] = [0..8, 8..16];
assert_eq(u32:0 ++ u32:8, data[0][0] ++ data[1][0]);
}
```
```
0313: fn test_array2d_tiv2() {
0314: let data: u32[8][2] = [0..8, 8..16];
0315: assert_eq(u32:0 ++ u32:8, data[0][0] ++ data[1][0]);
~~~~~~~~~~~~~~~~~~~^----------------------------------------^ FailureError: The program being interpreted failed!
lhs: u64:8
rhs: u9:8
were not equal
0316: }
```

**Expected behavior**

I would expect `[0..8, 8..16]` to get coerced into `u32[8][2]`.

Note that annotating the range expression will work around this issue
```
#[test]
fn test_array2d_tiv2() {
let data: u32[8][2] = [u32:0..u32:8, u32:8..u32:16];
assert_eq(u32:0 ++ u32:8, data[0][0] ++ data[1][0]);
}
```

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.