Files
sx/examples/basic/0042-basic-block-value-destructure.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

26 lines
769 B
Plaintext

// 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 :: () -> (i32, i32) { (5, 7) }
main :: () -> i32 {
// 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
}