Files
sx/examples/errors/1051-errors-cleanup-closure-boundary.sx
agra 989e18b760 feat: tuple syntax cutover — Tuple(...) type + .(...) value
Replace the bare-paren tuple grammar with explicit, position-unambiguous
forms, mirroring how structs work:

  type     `(A, B)`        -> `Tuple(A, B)`          (named keeps `:`)
  value    `(a, b)`        -> `.(a, b)`              (named uses `=`)
  typed    (new)           -> `Tuple(A, B).(a, b)`   (like `Point.{...}`)
  failable `-> (T, !)`     -> `-> T !`
           `-> (T1, T2, !)`-> `-> Tuple(T1, T2) !`   (channel outside Tuple)

Bare `(...)` is now grouping only, everywhere; a comma in bare parens is a
hard error with a migration hint. Grouping, function types `(A, B) -> R`,
param lists, lambdas, and match bindings are unaffected.

`Tuple(...)` is strictly a TYPE in every position (including `size_of` /
`type_info` args); a tuple VALUE comes only from `.(...)` (anonymous) or
`Tuple(...).(...)` (explicitly typed). A bare `Tuple(1, 2)` is a tuple
type with non-type elements -> rejected.

The ~110 tuple-bearing corpus files were migrated with a one-shot
AST-aware migrator (the `sx migrate` tool from the prior commit, removed
here). New examples: 0130 (new syntax), 0131 (typed construction), 1060
(named-tuple failable return). 1116 golden updated for the new hint text.
2026-06-25 17:53:57 +03:00

49 lines
1.8 KiB
Plaintext

// A closure literal inside a `defer` / `onfail` body is its OWN function
// boundary (ERR step E1.7). Two boundary effects, both pinned here:
//
// (a) `checkCleanupNode` sees a bare lambda STATEMENT as a `.lambda` node and
// STOPS — it does not descend into the lambda body. So the bare failable
// inside the lambda is the lambda's concern, not a cleanup violation
// (were the `.lambda` arm to recurse, this bare `failing()` would reject
// like the ones in 1052).
//
// (b) value-slot liveness (E1.8) is analysed per-boundary: `flowExpr` recurses
// into the lambda via `analyzeFnBody`, so a value slot read inside the
// lambda must prove its own error absent — `v` here is live under its
// `if !err` guard. (The rejecting counterpart is 1053.)
//
// Also: `try` is legal inside the lambda (it propagates through the lambda's own
// `!E` channel) even though it is parser-banned in the cleanup body directly.
//
// Locks the closure-boundary arms of the error-flow pass before A5.2 extracts it
// into its own module. Constructible since issue 0073 (closure literal in a
// `defer` body no longer segfaults lowering — see 0310).
#import "modules/std.sx";
E :: error { Bad }
failing :: () -> !E { raise error.Bad; }
recover :: () -> i32 !E { return 21; }
work :: () {
defer {
// (a) bare lambda statement — checkCleanupNode stops at the `.lambda`.
() -> !E { failing(); };
// (b) called closure — its body is analysed as its own boundary.
emit := () -> !E {
v, err := recover();
if !err { print("defer closure: v={}\n", v); } // E1.8: live under guard
try failing();
};
emit() catch (e) print("defer closure: raised\n");
}
print("body\n");
}
main :: () -> i32 {
work();
return 0;
}