Skip to content

feat(validation): warn on array initialization with fewer elements than expected#1645

Open
ghaith wants to merge 8 commits intomasterfrom
array_init_validation
Open

feat(validation): warn on array initialization with fewer elements than expected#1645
ghaith wants to merge 8 commits intomasterfrom
array_init_validation

Conversation

@ghaith
Copy link
Copy Markdown
Collaborator

@ghaith ghaith commented Mar 26, 2026

Add warning E127 when an array initializer provides fewer values than the declared size. The remaining elements are zero-initialized, but this may be unintentional, so a warning is emitted.

Also fix a codegen crash when an array literal contains exactly one element (e.g. ARRAY[0..3] OF INT := [11]). The issue was that generate_literal_array resolved the type hint from the inner element node (giving e.g. INT) instead of the array literal node. The function now accepts an explicit type hint from the call site.

  • Register E127 as Warning in the diagnostics registry
  • Add fewer-elements check in validate_array() (src/validation/array.rs)
  • Fix generate_literal_array to accept optional type hint override
  • Add unit tests for 1D, 2D, nested, struct, and multiplied cases
  • Add lit tests for single-element init and partial init zero-padding
  • Reword E043 message for consistency

…an expected

Add warning E127 when an array initializer provides fewer values than
the declared size. The remaining elements are zero-initialized, but
this may be unintentional, so a warning is emitted.

Also fix a codegen crash when an array literal contains exactly one
element (e.g. `ARRAY[0..3] OF INT := [11]`). The issue was that
`generate_literal_array` resolved the type hint from the inner
element node (giving e.g. INT) instead of the array literal node.
The function now accepts an explicit type hint from the call site.

- Register E127 as Warning in the diagnostics registry
- Add fewer-elements check in `validate_array()` (src/validation/array.rs)
- Fix `generate_literal_array` to accept optional type hint override
- Add unit tests for 1D, 2D, nested, struct, and multiplied cases
- Add lit tests for single-element init and partial init zero-padding
- Reword E043 message for consistency
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ghaith ghaith requested a review from mhasel April 2, 2026 07:54
@ghaith ghaith force-pushed the array_init_validation branch from a142059 to 83416fb Compare April 2, 2026 11:19
@ghaith ghaith requested a review from Copilot April 2, 2026 11:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 34 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/validation/types.rs:1

  • This use item is likely to be reformatted by rustfmt (it’s currently a single long line within the brace group). Running cargo fmt (or manually splitting imports across lines) will keep formatting consistent and reduce churn in future diffs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants