Files
sx/examples/1121-diagnostics-reserved-name-control-flow.sx
agra 116af2359e lang: multi-iterable for loops — drop ':', add '..=', open ranges, arrow bodies
The for header is now a comma-separated list of iterables with a
positional capture group and no ':' separator:

    for xs (x) { }                    // collection
    for 0..n (i) { }                  // range (end exclusive)
    for 1..=5 (a) { }                 // ..= inclusive end
    for xs, 0.. (x, i) { }            // index idiom (replaces (x, i))
    for xs, ys (x, y) { }             // parallel (zip) iteration
    for xs (x) => sum += x;           // arrow body (full statement)

First-iterable-wins: the first iterable's length drives the loop and
must be bounded; the other positions follow by their own cursors (a
non-first range's end is not consulted or evaluated; a shorter
non-first collection is read past its length on mismatch). The old
single-iterable index capture is replaced by the trailing open range.

Capture/call disambiguation is positional: the paren group immediately
before '{' or '=>' is the capture, every earlier top-level group is a
call. 'for zip(a, b) (x, y)' calls zip; 'for f(n) { }' reads (n) as
the capture and errors with a parenthesize/add-capture hint. The old
':' form errors with a migration hint.

Lowering is unified across forms: one cursor slot per position (ranges
start at their start, collections at 0), all advanced together, the
first position's bound terminating. inline for keeps the single
bounded comptime range.

Migrated the full corpus (examples, library modules, issue repros,
in-source test strings). New coverage: examples/0050 (the full feature
surface) and examples/1149-1155 (seven diagnostic faces). specs.md For
Loop section + grammar rewritten; readme teaser updated.
2026-06-10 20:30:55 +03:00

31 lines
1.4 KiB
Plaintext

// Reserved/builtin type names are rejected as binding NAMES across every
// control-flow and destructuring form, not just plain `var`/param decls: a
// destructure name (`s2`), an `if`/`while` optional binding (`u8`/`s16`), a
// `for` capture and index name (`bool`/`s32`), and a match-arm capture
// (`string`). Each spelling parses as a `.type_expr`, so the address-of family
// in lowering mis-lowers it (a loaded aggregate passed by value to a `ptr`
// param → LLVM verifier abort). The declaration-site diagnostic comes from one
// EXHAUSTIVE binding-name walk, so no syntactic binding form can slip through.
//
// Regression (issue 0076, attempt-4 coverage). Expected: one error per
// offending name; exit 1 — NOT an LLVM verifier abort.
#import "modules/std.sx";
pair :: () -> (s64, s64) { (1, 2) }
maybe :: () -> ?s64 { return null; }
main :: () -> s32 {
s2, rest := pair(); // destructure name
if u8 := maybe() { } // if optional binding
while s16 := maybe() { break; } // while optional binding
xs := [3]s64.{ 10, 20, 30 };
for xs (bool) { } // for capture name
for xs, 0.. (v, s32) { } // for index name
opt: ?s64 = 5;
r := if opt == { // match-arm capture
case .some: (string) { 0 }
case .none: { 0 }
};
return 0;
}