Skip to content

fix(flowc): DOTDOT lex, for-range check, newline struct fields, array<T> - #437

Merged
godofecht merged 2 commits into
mainfrom
work
Aug 12, 2026
Merged

godofecht merged 2 commits into
mainfrom
work

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Summary

  • compiler/src/lexer.flow: fix TOK_DOTDOT off-by-one. The initial flowc_lexer_bump already consumed the first dot, so only one more bump was needed. Two extra bumps skipped the first digit of the number after ...
  • compiler/src/parser.flow: use check_kw/check instead of eat_kw/eat for the for-loop range separator. eat_kw sets err=1 on failure, which prevented the TOK_DOTDOT fallback from ever succeeding. Also allow newline-separated struct fields (no comma required).
  • compiler/src/cgen.flow: lower array<T> (no size, ival == 0) to T* in flowc_cgen_emit_type, matching the Python compiler's pointer lowering for unsized array parameters.
  • compiler/bootstrap/flowc_stage_a.c: regenerated.

Context

for i in 0..10 { } always failed because the .. lexer skipped a character and the for-loop parser set an error flag on the KW_TO check before trying TOK_DOTDOT. Struct fields without commas (common in the stdlib) also failed. Unsized array<T> parameters produced unknown type name 'array' in the C output.

Test plan

  • ./flow run compiler/src/main.flow passes (flowc: PASS)
  • Three consecutive generation fixed-points pass (byte-identical)
  • lib/stdlib/array.flow compiles to valid C with zero clang errors
  • lib/stdlib/option.flow compiles to valid C with zero clang errors
  • lib/stdlib/result.flow compiles to valid C with zero clang errors
  • for i in 0..5 { println(i) } prints 0 1 2 3 4

This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.

Generated with Devin

godofecht and others added 2 commits August 12, 2026 00:51
The root cause of #431 was a hardcoded struct size (24 bytes) that
didn't account for C alignment padding. CVSplit has two ptr<i32>
(8 bytes each) and two i32 (4 bytes each). Naive sum is 24, but the
C compiler inserts 4 bytes of padding after n_train to align
test_indices, and 4 bytes after n_test to align the next array
element. The real sizeof is 32.

The generated C code was always correct. The struct copy, pointer
field access, and free all work when the allocation is sized
properly. Under-allocation caused the heap-buffer-overflow.

The test uses the correct size (32) and passes clean under
AddressSanitizer. Documents the alignment pitfall in the test
header so future users reach for sizeof<T>() or calloc instead of
hardcoding.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
compiler/src/lexer.flow: fix TOK_DOTDOT off-by-one. The initial
flowc_lexer_bump already consumed the first dot, so only one more
bump is needed for the second dot. Two extra bumps skipped the first
digit of the number after ..

compiler/src/parser.flow:
- Use check_kw/check instead of eat_kw/eat for the for-loop range
  separator. eat_kw sets err=1 on failure, which prevented the
  TOK_DOTDOT fallback from ever succeeding.
- Allow newline-separated struct fields (no comma required). If the
  next token after a field type is an identifier or }, continue
  instead of erroring.

compiler/src/cgen.flow: lower array<T> (ival == 0, no size) to T*
in flowc_cgen_emit_type, matching the Python compiler's pointer
lowering for unsized array parameters.

compiler/bootstrap/flowc_stage_a.c: regenerated.

lib/stdlib/array.flow, option.flow, result.flow now compile to
valid C with zero errors.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@cursor

cursor Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@godofecht
godofecht merged commit 9f8520a into main Aug 12, 2026
12 of 13 checks passed
@godofecht
godofecht deleted the work branch August 12, 2026 00:39
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.

1 participant