Files
sx/examples/0514-packs-pack-type-position.sx
agra 4e942b5373 test: migrate examples to XXXX-category-name layout + split expected streams
Rename all example tests/companions to the XXXX-category-test-name scheme
(per-category 100-blocks: basic 0010, types 0100, ... errors 1000,
diagnostics 1100, ffi 1200, ffi-objc 1300, ffi-jni 1400, vectors 1500,
platform 1600). Companions and dir/C fixtures move in lockstep with their
parent test; #import/#source/#include paths rewritten to match.

Expected output now lives in examples/expected/ (a sibling dir of the
tests) split into three streams per the new convention:
  <name>.exit / <name>.stdout / <name>.stderr  (+ optional <name>.ir)

run_examples.sh rewritten: scans examples/ and issues/ for an
expected/<name>.exit marker, captures stdout and stderr separately (no
more 2>&1), compares each stream + exit + optional IR snapshot.

Behavior validated unchanged: every renamed test reproduces its prior
merged output + exit (diffs limited to file paths/basenames embedded in
diagnostics + traces, which correctly reflect the new names). Suite:
292 passed, 0 failed. 50-smoke.sx split + issue relocation + docs follow
in subsequent commits.
2026-06-01 19:05:15 +03:00

40 lines
1.5 KiB
Plaintext

// Variadic heterogeneous type packs — step 3: `$args[$i]` in
// type positions.
//
// `$args[$i]` resolves to the i-th element type of the active
// pack binding wherever a type expression is expected:
// - return type: `-> $args[0]`
// - local var annotation: `x : $args[1] = ...`
// - (later: param types, fn-pointer types, struct field types)
//
// Today's parser hits "expected '{'" at the `$args[0]` token in
// the return type position because the `$<ident>` arm only
// accepts plain generic names; `[<int>]` after the name isn't
// recognised. This file pins that rejection. Next commit teaches
// the parser to accept `$<pack>[<int>]` and adds a new
// `PackIndexTypeExpr` AST node; `resolveTypeWithBindings`
// consults the active `pack_arg_types` map.
//
// The body intentionally exercises TWO positions per mono — the
// return type AND a local annotation — so the parser change has
// to cover more than just the trailing return arrow.
#import "modules/std.sx";
swap_take :: (..$args) -> $args[0] {
second : $args[1] = args[1];
// `second` is bound and typed — confirms the local-annotation
// path also resolves. The body returns args[0] (statically
// typed as $args[0]).
return args[0];
}
main :: () -> s32 {
// Heterogeneous call shapes — each picks a different concrete
// pair, gets its own mono.
a : s64 = swap_take(42, "ignored"); // $args[0] = s64, $args[1] = string
b : string = swap_take("first", 99); // $args[0] = string, $args[1] = s64
print("{} {}\n", a, b);
return 0;
}