feat(validation): warn on array initialization with fewer elements than expected#1645
Open
feat(validation): warn on array initialization with fewer elements than expected#1645
Conversation
…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
There was a problem hiding this comment.
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.
mhasel
requested changes
Mar 31, 2026
a142059 to
83416fb
Compare
There was a problem hiding this comment.
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
useitem is likely to be reformatted byrustfmt(it’s currently a single long line within the brace group). Runningcargo 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 thatgenerate_literal_arrayresolved 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.validate_array()(src/validation/array.rs)generate_literal_arrayto accept optional type hint override