Propagate annotated widths into range literals in nested arrays (Re: #3564) #3597
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey team!
While looking into #3564, I tracked the bug down to the DSLX type inference for array literals. A range like 0..8 infers the narrowest bit width needed for its endpoints, and when I wrote
let data: u32[8][2] = [0..8, 8..16];the outer annotation only enforced the shape, not the inner element width. Because the type checker only propagated the annotated element type into top‑level literal numbers, theRangemembers kept their narrow widths, so data[0][0] wasn’t a u32 and the assertion failed with mismatched widths.I fixed this by extending the existing propagation... when an array literal has an annotation, we now also push that annotated element type down into the start and end of any unannotated
Rangemembers (resolving through one level if the element type itself is an array). With the endpoints coerced to the target bits type, theRangededuces to the right element width and the nested array becomes u32[8][2] as annotated.I added a regression test mirroring the original repro to lock in the behavior.
Thanks in advance for the review. Wishing everyone a bug free and relaxing holiday season!
Fixes: #3564