Skip to content

[#340] Unify type definition syntax: use {} for all type fields#342

Merged
milkyskies merged 2 commits intomainfrom
feature/#340.unified-type-syntax
Mar 18, 2026
Merged

[#340] Unify type definition syntax: use {} for all type fields#342
milkyskies merged 2 commits intomainfrom
feature/#340.unified-type-syntax

Conversation

@milkyskies
Copy link
Owner

closes #340

Summary

  • Records: type User = { ... }type User { ... } (no = needed)
  • Unions: type Shape = | Circle(r: number) | Pointtype Shape { | Circle { r: number } | Point }
  • Newtypes: type OrderId = OrderId(number)type OrderId { number }
  • Aliases/string unions: unchanged, still use =

One syntax for fields: { } always means "here are the fields/variants." | inside means union, name: type means record.

Changes

Compiler:

  • Parser: type Name { goes to new parse_type_body_in_braces() which disambiguates record/union/newtype by peeking at first token inside {}
  • Union variant fields: { } instead of ( )
  • Lowering: handles newtype case (VARIANT_FIELD directly in TYPE_DEF_UNION)
  • Formatter: emits new syntax

All .fl files: 24 files updated (fixtures, examples, inline test strings)

Docs: design.md, llms.txt, 10 site pages

Syntax highlighting: tree-sitter grammar + tests

Test plan

  • All 888 tests pass
  • cargo fmt clean
  • cargo clippy -- -D warnings clean
  • RUSTFLAGS="-D warnings" cargo test clean
  • Verify store and todo-app render correctly
  • Verify syntax highlighting in VSCode

🤖 Generated with Claude Code

milkyskies and others added 2 commits March 18, 2026 20:02
Records: `type User = { ... }` -> `type User { ... }` (no = needed)
Unions: variant fields use {} instead of (): `| Circle { radius: number }`
Unions wrapped in {}: `type Shape { | Circle { r: number } | Point }`
Newtypes: `type OrderId = OrderId(number)` -> `type OrderId { number }`
Aliases/string unions unchanged: still use =

Parser disambiguates inside {}: | = union, name: = record, bare type = newtype.
Removed is_newtype_constructor heuristic.

Updated all .fl files, test fixtures, example apps, and inline test strings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- design.md: all type definitions, codegen tables, resolved decisions
- llms.txt: records, unions, newtypes, banned keywords table
- site docs: 10 pages updated (guide + reference)
- tree-sitter: = optional in type_declaration, variant fields use {}
- tree-sitter tests: updated declaration corpus

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@milkyskies milkyskies merged commit 9303085 into main Mar 18, 2026
2 checks passed
@milkyskies milkyskies deleted the feature/#340.unified-type-syntax branch March 18, 2026 12:53
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.

Unify type definition syntax: use {} for all type fields

1 participant