Files
sx/examples/route/0822-route-all-own-wins-surfaces.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

40 lines
1.3 KiB
Plaintext

// G3 — own-wins HALVES for the route-all surfaces 0815 covered only on the
// ambiguous half. `main` authors its OWN `Box { m }` and flat-imports `dep.sx`
// (`Box { a }`); each surface below must bind main's OWN `Box`, observed by a
// `.m` access (disjoint field sets → a wrong-author binding is a hard compile
// error). Complements 0816 (which covered only the union body-builder child):
// - pointer wrapper-alias element `BoxPtr :: *Box`
// - tuple element `(Box, i32)`
// - enum body-builder child `WrapE :: enum { V: Box }`
// - inline-anonymous union child `x : union { b: Box }`
#import "modules/std.sx";
#import "0822-route-all-own-wins-surfaces/dep.sx";
Box :: struct { m: i32; }
BoxPtr :: *Box;
WrapE :: enum { V: Box; }
main :: () -> i32 {
own : Box = ---;
own.m = 10;
// *Named wrapper-alias element own-wins
bp : BoxPtr = @own;
// tuple element own-wins
t : Tuple(Box, i32) = ---;
t.0.m = 12;
// enum body-builder child own-wins (payload must be main's `Box`)
we : WrapE = .V(own);
ev := we.V.m;
// inline-anonymous union child own-wins
x : union { b: Box; n: i32 } = ---;
x.b.m = 13;
print("bp={} t={} ev={} x={} dep={}\n", bp.m, t.0.m, ev, x.b.m, dep_box());
0
}