anonymous struct payloads

This commit is contained in:
2026-06-30 23:01:18 +02:00
parent eb06b2ee62
commit d6f9c24314
6 changed files with 317 additions and 38 deletions
+11 -4
View File
@@ -595,7 +595,13 @@
- named fallible signatures can use inline unbacked enum and `union(enum)` error types
after `!`
23.7. anonymous struct payloads and keyed payload sugar
23.7. anonymous struct payloads and keyed payload sugar (implemented)
- tagged-union variants can use anonymous `struct { ... }` payloads, scoped to variant payload
declarations rather than general anonymous type syntax
- contextual `.variant{field = value, ...}` constructs struct payloads by key, reusing ordinary
struct-literal validation for unknown, duplicate, missing, and mismatched fields
- structurally identical anonymous struct payloads share type identity, so sum composition merges
matching variants and still rejects same-name variants with different payload shapes
24. dynamic heap allocation
- see below for direction
@@ -978,7 +984,7 @@ message :: match code {
Brolang handles errors as values. There is no hidden control flow — a function that can fail declares this in its signature, and the caller must explicitly handle the possibility of failure.
Milestone 23 v1 implements named error channels, native sum composition, `return`-based error dispatch, exact-channel `try`, and fallback `catch`. Milestone 23.5 adds `catch |e|` blocks and `try` widening across composable error channels. Milestone 23.6 adds contextual payload construction and inline error types. It still defers the `error` keyword shorthand, anonymous struct payload sugar, and match-on-error shorthand.
Milestone 23 v1 implements named error channels, native sum composition, `return`-based error dispatch, exact-channel `try`, and fallback `catch`. Milestone 23.5 adds `catch |e|` blocks and `try` widening across composable error channels. Milestone 23.6 adds contextual payload construction and inline error types. Milestone 23.7 adds anonymous struct payloads and keyed payload sugar. It still defers the `error` keyword shorthand and match-on-error shorthand.
### Fallible Functions
@@ -1081,7 +1087,7 @@ parse_section func(p: @mut Parser) void ! ParseError {
# ... parsing logic ...
if p.pos >= p.input.len or p.input[p.pos] != ']' return .unclosed_section{start_line}
if p.pos >= p.input.len or p.input[p.pos] != ']' return .unclosed_section{line = start_line}
# ... continue on success ...
}
@@ -1177,7 +1183,8 @@ data :: read_file(path) catch |e| match e {
| `T ! (E1 | E2)` | Planned direct spelling with parentheses; use a named alias in v1 |
| `return e` | Exit function via error channel when `e : E` |
| `error e` | Planned shorthand, not v1 |
| `.variant{payload}` | Construct a payload-carrying tagged-union variant from context |
| `.variant{payload}` | Construct a payload-carrying tagged-union variant from one payload expression |
| `.variant{field = value, ...}` | Construct a struct-payload tagged-union variant from context |
| `error .variant{...}` | Planned shorthand, not v1 |
| `try expr` | Unwrap success or propagate an exact/sum-widenable error channel |
| `expr catch fallback` | Provide fallback value on error |