errdefer and try/defer fix

This commit is contained in:
2026-07-13 19:20:22 +02:00
parent 9e75549d02
commit 6de4d9f9f3
23 changed files with 113190 additions and 105482 deletions
+9 -4
View File
@@ -300,6 +300,9 @@
- `defer <stmt>` runs the statement when the enclosing block scope exits, in reverse
(LIFO) order, on every exit path: fall-through, `return`, `break`, `continue`. The
deferred statement may be a block (`defer { ... }`)
- `errdefer [|error|] <stmt>` is the fallible-function counterpart: it runs only when
an explicit or `try`-propagated error exits its active block scope, can capture the
widened enclosing error, and stays interleaved with ordinary defers in LIFO order
- bare block statements `{ ... }` were added as the enabling feature: a `{ ... }`
introduces a nested scope (locals are name-scoped to it; defers inside it fire at the
closing brace). A leading `{` is unambiguous since struct literals are postfix only
@@ -310,10 +313,8 @@
the innermost loop body; fall-through flushes the current block's own defers. Deferring
a `return`/`break`/`continue`/`defer`, a `return` inside a `defer`, or a `break`/
`continue` that would escape a `defer` are all rejected
- implemented entirely in lexer/parser/checker (new `Keyword_Defer`; `Block`/`Defer` AST
kinds reusing `body`/`update`; `parse_block_statement`/`parse_defer`). No HIR opcode:
a bare block is built and spliced inline, and a deferred statement is built once at the
`defer` site and its hir replayed at each exit, so lowering/codegen are unchanged
- cleanup is statically expanded with no runtime registration stack; `try` carries its
active error-exit cleanup into lowering so propagation cannot bypass either defer form
20. add `yield` statement (implemented; first pass — value blocks only; see below)
- a `{ ... }` on the right of a declaration or assignment is a *value block*: its final
@@ -823,6 +824,10 @@
conflicting targets
- root `std` re-exports only `ArrayList(T)` for now; operations remain under `std/arraylist`
35. syntax highlighting (tree-sitter) updates (implemented)
- pointer sigils are highlighted as operators
- type-factory calls in type positions and struct literals are highlighted as functions
## A word on unchecked casts
For casts that bypass safety checks, Honey provides builtin functions: