fix(0123): wrong arg counts to fixed-arity fns error at the call site

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.
This commit is contained in:
agra
2026-06-12 01:42:59 +03:00
parent 7d1e23ecc6
commit 7f2b8b5cde
12 changed files with 190 additions and 3 deletions

View File

@@ -0,0 +1,33 @@
// 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
}

View File

@@ -0,0 +1,26 @@
// Wrong argument counts to fixed-arity functions are rejected at the call
// site — bare calls, flat-imported stdlib fns, method dot-calls, and ufcs
// dot-calls — instead of reaching LLVM verification ("Incorrect number of
// arguments passed to called function!").
// Regression (issue 0123).
#import "modules/std.sx";
add2 :: (a: s64, b: s64) -> s64 { return a + b; }
Point :: struct {
x: s64;
scaled :: (self: Point, k: s64) -> s64 { return self.x * k; }
}
bump :: ufcs (p: Point, by: s64) -> s64 { return p.x + by; }
main :: () -> s32 {
_ = add2(1, 2, 3); // plain bare call, too many
_ = add2(1); // plain bare call, too few
_ = concat("a", "b", "c"); // flat-imported stdlib fn, too many
p := Point.{ x = 5 };
_ = p.scaled(2, 9); // method dot-call, too many
_ = p.bump(1, 2); // ufcs dot-call, too many
return 0;
}

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,7 @@
10
15
15
6
0
6
true

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,29 @@
error: 'add2' expects 2 arguments, but 3 were given
--> examples/1167-diagnostics-call-arity-mismatch.sx:19:9
|
19 | _ = add2(1, 2, 3); // plain bare call, too many
| ^^^^
error: 'add2' expects 2 arguments, but 1 was given
--> examples/1167-diagnostics-call-arity-mismatch.sx:20:9
|
20 | _ = add2(1); // plain bare call, too few
| ^^^^
error: 'concat' expects 2 arguments, but 3 were given
--> examples/1167-diagnostics-call-arity-mismatch.sx:21:9
|
21 | _ = concat("a", "b", "c"); // flat-imported stdlib fn, too many
| ^^^^^^
error: 'Point.scaled' expects 1 argument, but 2 were given
--> examples/1167-diagnostics-call-arity-mismatch.sx:23:9
|
23 | _ = p.scaled(2, 9); // method dot-call, too many
| ^^^^^^^^
error: 'bump' expects 1 argument, but 2 were given
--> examples/1167-diagnostics-call-arity-mismatch.sx:24:9
|
24 | _ = p.bump(1, 2); // ufcs dot-call, too many
| ^^^^^^

View File

@@ -0,0 +1 @@