Repository navigation
fix(compiler): reject invalid array sizes - #1078
Conversation
Check resolved array counts before memory planning. Reject fractional negative and nonfinite values with a semantic diagnostic at the source declaration. Apply the check to module and prototype arrays. Keep zero length arrays and whole numeric values such as 1.0 valid. Fixes 8f4e#1063
irimias57
left a comment
There was a problem hiding this comment.
Thank you for the contribution, Nigel—and welcome! This is a strong first contribution: the implementation is focused, the diagnostic is attached to the original declaration, and the coverage is thoughtful.
I would like one change to how the end-to-end compiler behavior is tested. Please express these cases as 8f4e source fixtures so the language behavior is documented and exercised through the repository fixture conventions:
- Put rejected-size cases under
packages/compiler/tests/errors/as*.error.8f4efixtures, which will snapshot the diagnostic code, message, source line, and project context. - Cover accepted boundary cases such as
0and1.0in a*.test.8f4efixture with native assertions. - The focused memory-planner unit test can remain for the compact, parameterized coverage across every array instruction and values such as NaN and infinity that are awkward to express as source fixtures.
In other words, this is primarily a request to move the public compiler regression coverage out of arraySizes.test.ts and into the source fixture suites; the lower-level unit coverage is still useful.
Replace the public TypeScript regressions with source fixtures. Snapshot diagnostics for invalid sizes and exercise valid sizes with native assertions. Keep the planner unit coverage unchanged. Prepared with Codex assistance.
irimias57
left a comment
There was a problem hiding this comment.
Thank you again for the contribution, Nigel, and for responding so thoughtfully to the review! The fixture-based regressions now exercise the behavior through the repository's language-level test conventions, while retaining the useful focused planner coverage. Everything looks good.

int[] values 0.5used to compile with a fractional memory layout. Array sizes now have to resolve to finite nonnegative whole numbers before layout planning.The check covers constants and expressions in modules and prototypes. Diagnostics point to the original array declaration and its project block. Zero length arrays and whole values such as
1.0remain valid.Compiler regressions now use source fixtures. Nine
*.error.8f4ecases snapshot the diagnostic code and message along with the declaration line and project context. A*.test.8f4efixture uses native assertions to cover all 14 array instructions with0and1.0and3plus accepted prototype boundaries. The planner unit coverage remains in place for every array instruction and values such as NaN and infinity.Fixes #1063
All affected lint checks and type checks and tests passed locally. The focused run across five compiler and test packages passed 497 tests.
Tested with Node 24.16.0 and npm 11.13.0. Nx used local caching and ran plugins in process.
Prepared with Codex assistance.