google / google/xls

parser error when declaring array of fully qualified foreign types

Open
#2,726 0 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**
It seems that the parser error out when declaring array of foreign types that include the module prefix.

**To Reproduce**

This snippets:
```
import float32;

const F32_ZERO = float32::F32 {
sign: u1:0,
bexp: u8:0,
fraction: u23:0,
};

const F32_ZEROES = float32::F32[4][4]:[
[F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO],
[F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO],
[F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO],
[F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO],
];
```
Produces this error:
```
0011: const F32_ZEROES = float32::F32[4][4]:[[F32_ZERO, ...], [F32_ZERO, ...], [F32_ZERO, ...], [F32_ZERO, ...]];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^---^ ParseError: Type before ':' for presumed array literal was not a type definition; got `float32::F32[4]` (kind: index)
```

**Additional context**

Note that creating a local type alias workaround this issue, ex:
```
import float32;

type F32 = float32::F32;
const F32_ZERO = F32 {
sign: u1:0,
bexp: u8:0,
fraction: u23:0,
};

const F32_ZEROES = F32[4][4]:[
[F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO],
[F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO],
[F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO],
[F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO],
];
```

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.