Skip to content

Parse array repeat initializers [value; N] (#585) - #609

Merged
godofecht merged 1 commit into
mainfrom
feat-array-repeat
Aug 20, 2026
Merged

godofecht merged 1 commit into
mainfrom
feat-array-repeat

Conversation

@godofecht

@godofecht godofecht commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #585. unverified: 183 -> 179.

The gap

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.

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 call compute four times rather than once. Silently doing that is worse than refusing it, and it is the same trap that made sum(range) evaluate its bounds eleven times in #536.

Each says which rule it hit rather than reporting a syntax error:

the value in [value; N] must be a literal, because it is written out once
per element rather than evaluated once

the length in [value; N] must be an integer literal or a const
the length in [value; N] cannot be negative
[value; N] is limited to 65536 elements; this asks for 1000000

A knock-on effect worth noting

Two blocks in docs/language/lifetime-domains.md used [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 a text fence directly below:

error: lifetime domain escape: `scratch` lives in the `callback` domain but is
       stored in `tail`, which lives in the `application` domain

Tagged expect-error, so the page now checks its own quoted output.

Verification

Check Result
pytest tests/ 1712 passed, 6 skipped
./flow test --tier2 --strict 691/691
check_doc_examples.py --check-ledger no new unverified, 183 → 179
ruff check src clean

Eight 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.py failed 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.

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]>
@godofecht
godofecht merged commit 69e511d into main Aug 20, 2026
22 checks passed
@godofecht
godofecht deleted the feat-array-repeat branch August 20, 2026 08:15
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.

Parser rejects documented array repeat initializers [value; N]

1 participant