issues/0065: RESOLVED — value-block destructure parses

The block-value rework routes value-position `{ … }` through the same
statement parser as every other block, so a destructure decl (and any
statement form) inside a value-bound block now parses, with the trailing
expression as the block's value. The `defer { … }` half was fixed
earlier (634cf9b). Regression: examples/0042-basic-block-value-destructure.sx.

Gates: zig build test, run_examples.sh -> 344 passed.
This commit is contained in:
agra
2026-06-02 09:31:18 +03:00
parent bdd0e96d78
commit 92dba9078c
5 changed files with 38 additions and 9 deletions

View File

@@ -0,0 +1,25 @@
// A value-position block (`x := { … }`, a call argument, …) parses any
// statement form in its body — including a destructure decl — and yields its
// trailing expression as the value. Previously a braced value block routed
// through a restricted expression parser that rejected destructures with
// "expected ';'".
//
// Regression (issue 0065).
#import "modules/std.sx";
pair :: () -> (s32, s32) { (5, 7) }
main :: () -> s32 {
// destructure decl inside a value-bound block
sum := {
a, b := pair();
a + b // trailing expression → the block's value
};
print("sum: {}\n", sum); // 12
// block expression directly as a call argument
print("sq: {}\n", { x := 4; x * x }); // 16
sum
}

View File

@@ -0,0 +1 @@
12

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,2 @@
sum: 12
sq: 16

View File

@@ -1,14 +1,14 @@
# 0065 — block-expression body does not parse a destructure decl (`v, e := f();`)
> **PARTIALLY RESOLVED (defer manifestation, this session).** A braced
> `defer { … }` body now parses via `parseBlock` (src/parser.zig, the
> `kw_defer` arm) instead of `parseExpr`, mirroring `onfail`. So
> `defer { v, e := f(); … }`, `defer { x() catch e … }`, and plain
> `defer { stmt; }` all parse and run. Regression:
> `examples/1050-errors-defer-block-body.sx`. **Still open:** the
> general *value-producing block in binding position*
> (`y := { v, e := f(); v };`) — a distinct parser path — does not parse
> a destructure decl; see the second reproduction below.
> **RESOLVED.** Two fixes landed:
> - The braced `defer { … }` body now parses via `parseBlock` (src/parser.zig,
> the `kw_defer` arm) instead of `parseExpr`, mirroring `onfail`. Regression:
> `examples/1050-errors-defer-block-body.sx` (commit `634cf9b`).
> - The general *value-producing block in binding position* fell out of the
> trailing-`;` block-value rework: value-position `{ … }` now routes through
> the same statement parser as every other block, so a destructure decl (and
> any statement form) parses, and the trailing expression is the block's
> value. Regression: `examples/0042-basic-block-value-destructure.sx`.
## Symptom