Repository navigation
Parse array repeat initializers [value; N] (#585) - #609
Merged
Merged
Conversation
The documentation has presented this as ordinary Flow since the book was
written:
let mut signal: array<f32, 256> = [0.0; 256]
The parser said `Expected TokenType.RBRACKET, got TokenType.SEMICOLON`.
The elements are written out at parse time, which decides the two
restrictions. The length must be an integer literal, because the elements
exist before anything is evaluated. The value must be a literal too: writing
out `[compute(); 4]` would call compute four times rather than once, and
silently doing that is worse than refusing it. Both say which rule they hit
rather than reporting a syntax error.
65536 elements is the cap. Beyond that the message says what was asked for,
instead of materializing an AST that size.
Also tags two blocks in docs/language/lifetime-domains.md expect-error. They
used `[0.0; 64]` and `[0; 8]`, so they could not parse; now that they can,
they reach the diagnostic each one exists to demonstrate, and the page quotes
that diagnostic in the text fence directly below.
unverified: 183 -> 179.
Closes #585
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
Closes #585.
unverified: 183 -> 179.The gap
The documentation has presented this as ordinary Flow since the book was written:
The parser said
Expected TokenType.RBRACKET, got TokenType.SEMICOLON.Two restrictions, both deliberate
The elements are written out at parse time, and that decides both:
The length must be an integer literal. The elements exist before anything is evaluated, so a runtime length has no meaning here.
The value must be a literal too.
[compute(); 4]would callcomputefour times rather than once. Silently doing that is worse than refusing it, and it is the same trap that madesum(range)evaluate its bounds eleven times in #536.Each says which rule it hit rather than reporting a syntax error:
A knock-on effect worth noting
Two blocks in
docs/language/lifetime-domains.mdused[0.0; 64]and[0; 8], so they could not parse at all. Now that they can, they reach the diagnostic each one exists to demonstrate, and the page quotes that diagnostic in atextfence directly below:Tagged
expect-error, so the page now checks its own quoted output.Verification
pytest tests/./flow test --tier2 --strictcheck_doc_examples.py --check-ledgerruff check srcEight parser tests and one that compiles and runs a program, asserting the values are actually there (
0.0 1.5 1 -2 -1) and that clang emits no warning.One note:
tests/integration/test_lsp_server.pyfailed once in a full-suite run and passes in isolation both with and without this change, so I am recording it as flaky rather than caused here.