fix(compiler): reject invalid array sizes by jinchuntan · Pull Request #1078 · 8f4e/8f4e · GitHub
Skip to content

fix(compiler): reject invalid array sizes - #1078

Merged
irimias57 merged 2 commits into
8f4e:mainfrom
jinchuntan:fix/invalid-array-sizes
Oct 17, 2026
Merged

irimias57 merged 2 commits into
8f4e:mainfrom
jinchuntan:fix/invalid-array-sizes

Conversation

@jinchuntan

@jinchuntan jinchuntan commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

int[] values 0.5 used 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.0 remain valid.

Compiler regressions now use source fixtures. Nine *.error.8f4e cases snapshot the diagnostic code and message along with the declaration line and project context. A *.test.8f4e fixture uses native assertions to cover all 14 array instructions with 0 and 1.0 and 3 plus 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.

npx nx affected --target=lint --base=284e4e34 --output-style=static
npx nx affected --target=typecheck --base=284e4e34 --output-style=static
npx nx affected --target=test --base=284e4e34 --output-style=static

Tested with Node 24.16.0 and npm 11.13.0. Nx used local caching and ran plugins in process.

Prepared with Codex assistance.

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
@andorthehood andorthehood added contributor compiler Compiler, tokenizer, codegen, and language-semantics work labels Oct 17, 2026

@irimias57 irimias57 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.8f4e fixtures, which will snapshot the diagnostic code, message, source line, and project context.
  • Cover accepted boundary cases such as 0 and 1.0 in a *.test.8f4e fixture 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.

Copy link
Copy Markdown
Contributor Author

@irimias57 irimias57 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@irimias57

Copy link
Copy Markdown
Member

@irimias57
irimias57 merged commit bac3184 into 8f4e:main Oct 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler Compiler, tokenizer, codegen, and language-semantics work contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject fractional array element counts before memory allocation

3 participants