Files
sx/examples/0044-basic-default-arg-expansion.sx
agra 297f127821 test(ir): lock call lowering with .ir snapshots + classification tests (A3.2 convergence step 1)
Test-first scaffolding before the CallPlan convergence — no call-code
change. Locks current call behavior so the later lowerCall rewrite is
guarded.

- .ir snapshots for representative call forms: 0031 (direct local-fn +
  dot-shorthand enum ctor), 0032 (UFCS/struct method), 0301 (closure/
  fn-pointer slot), 0400 (protocol dispatch + static-through-impl).
- New focused example 0044-basic-default-arg-expansion + .ir snapshot,
  pinning call-site default expansion (scale(5)->scale(ctx,5,2),
  label(1)->label(ctx,1,"v","!")). Foreign-class instance+static is
  already pinned by the existing FFI .ir set.
- Broaden calls.test.zig (scope-free classification): remaining reflection
  builtins, sqrt->f64, cast->resolved type arg, enum_literal->target_type.

1033 (#caller_location) was rejected as a snapshot: it embeds the absolute
source path as a length-typed string that normalize_ir can't reconcile;
default-arg coverage uses the path-free 0044 instead.

Gate green: zig build, zig build test, tests/run_examples.sh -> 357/0.
2026-06-02 19:20:14 +03:00

24 lines
865 B
Plaintext

// Call-site default-argument expansion (`appendDefaultArgs` / `expandCallDefaults`
// in lowerCall). A call that omits a trailing parameter with a default value
// has the default expression spliced in at the call site; an explicit argument
// overrides it. Two trailing defaults cover the "fill all remaining" path.
// Path-free IR (literal defaults) so the `.ir` snapshot is location-stable.
#import "modules/std.sx";
scale :: (n: s32, factor: s32 = 2) -> s32 { n * factor }
label :: (n: s32, prefix: string = "v", suffix: string = "!") -> s32 {
print("{}{}{}\n", prefix, n, suffix);
n
}
main :: () {
print("default: {}\n", scale(5));
print("explicit: {}\n", scale(5, 3));
_ = label(1); // both defaults filled
_ = label(2, "x"); // suffix default filled
_ = label(3, "y", "?"); // no defaults
}