Files
sx/examples/basic/0054-basic-dot-call-default-args.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

34 lines
1.1 KiB
Plaintext

// Trailing parameter defaults fill on method and ufcs dot-calls (the
// receiver-prepending dispatch paths), matching bare-call expansion (0044);
// a `#caller_location` default and a slice variadic keep their flexible
// arity under the call-arity check.
// Regression (issue 0123).
#import "modules/std.sx";
Point :: struct {
x: i64;
scaled :: (self: Point, k: i64 = 2) -> i64 { return self.x * k; }
}
bump :: ufcs (p: Point, by: i64 = 10) -> i64 { return p.x + by; }
sum_var :: (..xs: []i64) -> i64 {
t := 0;
for xs (x) { t = t + x; }
return t;
}
here :: (loc: Source_Location = #caller_location) -> i64 { return loc.line; }
main :: () {
p := Point.{ x = 5 };
print("{}\n", p.scaled()); // default filled on method dispatch
print("{}\n", p.scaled(3)); // explicit overrides
print("{}\n", p.bump()); // default filled on ufcs dispatch
print("{}\n", p.bump(1));
print("{}\n", sum_var()); // variadic: zero args
print("{}\n", sum_var(1, 2, 3)); // variadic: many args
print("{}\n", here() > 0); // #caller_location default
}