checkCallArity compares the supplied count against the declared params (min = params without trailing defaults, max = params.len, unbounded past a variadic) at the five plain dispatch sites in lowerCall — bare selected-author + lazy, namespace alias-gate + qualified, struct method, ufcs. Pack / comptime / generic / #compiler / #builtin callees keep their own dispatch. The method/ufcs sites also gain the appendDefaultArgs fill the generic-instance leg already had, so trailing defaults work on dot-calls instead of emitting under-arity calls. lowerStmt's local fn_decl arm now registers a pointer into the AST node in fn_ast_map, not a stack temporary that aliased every later local fn.
34 lines
1.1 KiB
Plaintext
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: s64;
|
|
scaled :: (self: Point, k: s64 = 2) -> s64 { return self.x * k; }
|
|
}
|
|
|
|
bump :: ufcs (p: Point, by: s64 = 10) -> s64 { return p.x + by; }
|
|
|
|
sum_var :: (..xs: []s64) -> s64 {
|
|
t := 0;
|
|
for xs (x) { t = t + x; }
|
|
return t;
|
|
}
|
|
|
|
here :: (loc: Source_Location = #caller_location) -> s64 { 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
|
|
}
|