contextual payload construction
This commit is contained in:
@@ -584,12 +584,18 @@
|
||||
- focused coverage lives in `examples/programs/errors` and the fallible ergonomics compiler test
|
||||
- leave ABI/layout/lint/design polish for later milestones
|
||||
|
||||
23.6. contextual payload construction + inline error types
|
||||
- implement contextual payload `.variant{...}` construction
|
||||
- allow named fallible signatures to use inline enum / tagged-union error types
|
||||
- settle qualified same-name disambiguation only if contextual construction needs it
|
||||
23.6. contextual payload construction + inline error types (implemented)
|
||||
- contextual payload `.variant{expr}` construction now works in tagged-union contexts
|
||||
(assignment, return, calls, and fallible error dispatch); bare `.variant` remains the
|
||||
spelling for void-payload variants
|
||||
- named fallible signatures can use inline unbacked enum and `union(enum)` error types
|
||||
after `!`
|
||||
- qualified same-name disambiguation remains deferred; existing ambiguous fallible return
|
||||
diagnostics cover the current surface
|
||||
|
||||
23.7. sum-type ABI/layout polish
|
||||
23.7. anonymous struct payloads and keyed payload sugar
|
||||
|
||||
23.8. sum-type ABI/layout polish
|
||||
- consider dynamic tag-width shrinking after the fixed-`u16` ABI has real pressure
|
||||
- consider all-void channel collapse after fallible channels are otherwise stable
|
||||
- define cross-module/global-id ABI determinism before multi-module builds depend on it
|
||||
@@ -976,7 +982,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. It still defers the `error` keyword shorthand, inline error types, contextual payload construction, 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. It still defers the `error` keyword shorthand, anonymous struct payload sugar, and match-on-error shorthand.
|
||||
|
||||
### Fallible Functions
|
||||
|
||||
@@ -1048,7 +1054,25 @@ ProcessError :: alias (IoError | ParseError)
|
||||
|
||||
### Inline Error Types
|
||||
|
||||
Inline error types are planned, but not part of milestone 23 v1. Use named enums, named tagged unions, or named aliases for now.
|
||||
Fallible signatures can define small private error channels inline:
|
||||
|
||||
```
|
||||
read_count func(path []u8) i32 ! union(enum) {
|
||||
not_found PathErrorInfo
|
||||
timeout_ms u64
|
||||
} { ... }
|
||||
```
|
||||
|
||||
Inline enums are also supported:
|
||||
|
||||
```
|
||||
parse_flag func(text []u8) bool ! enum {
|
||||
empty
|
||||
invalid
|
||||
} { ... }
|
||||
```
|
||||
|
||||
Use a named error type when the channel is shared or needs stable public identity.
|
||||
|
||||
### Returning Errors
|
||||
|
||||
@@ -1061,7 +1085,7 @@ parse_section func(p: @mut Parser) void ! ParseError {
|
||||
|
||||
# ... parsing logic ...
|
||||
|
||||
if p.pos >= p.input.len or p.input[p.pos] != ']' return ParseError{ unclosed_section = start_line }
|
||||
if p.pos >= p.input.len or p.input[p.pos] != ']' return .unclosed_section{start_line}
|
||||
|
||||
# ... continue on success ...
|
||||
}
|
||||
@@ -1071,7 +1095,7 @@ Since errors are just union values, you can also construct them separately:
|
||||
|
||||
```
|
||||
# Construct error value (it's just a union)
|
||||
e ParseError = ParseError{ timeout = 500 }
|
||||
e ParseError = .timeout{500}
|
||||
|
||||
# Return it via error channel later
|
||||
return e
|
||||
@@ -1157,6 +1181,7 @@ 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 |
|
||||
| `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 |
|
||||
|
||||
Reference in New Issue
Block a user