wcc: wwstage checks call arity at desugarcallargs
cstage rejects `add(1,2,3)` and `add(4)` (too many / not enough arguments); wwstage ran no count check at this seam, so both built -- a stray arg pushed silently, a missing one read garbage (cs-reject/ww-accept build-verdict divergence). Surplus errs when params exhaust with args left; missing errs on a leftover regular param (a leftover TK_ELLIPSIS or FFI "..." is a legal zero-arg variadic tail). fn-VALUE callees still bail at decl==nil -- their whole typecheck, arity included, stays task #51.
This commit is contained in:
@@ -6063,6 +6063,19 @@ fn desugarcallargs(c: *checker, n: *syntax.node) void = {
|
||||
let a: *syntax.node = n.list;
|
||||
for (a != nil) {
|
||||
let nexta: *syntax.node = a.next;
|
||||
// Arity, surplus side — params exhausted with args left
|
||||
// (variadics never exhaust: TK_ELLIPSIS absorbs without
|
||||
// advancing, the FFI "..." breaks out below). cstage errs
|
||||
// at check.c N_CALL `too many arguments`; wwstage ran no
|
||||
// count check at all, so `add(1,2,3)` built and pushed a
|
||||
// stray arg silently (cs-reject/ww-accept divergence).
|
||||
// fn-VALUE callees bail above decl==nil — task #51 owns
|
||||
// their whole typecheck, arity included.
|
||||
if (param == nil) {
|
||||
cerr("error: too many arguments\n");
|
||||
c.errs += 1;
|
||||
return;
|
||||
};
|
||||
if (param != nil) {
|
||||
if (param.kind == syntax.nkind.N_PARAM) {
|
||||
// C-style FFI variadic (bare `...`): str=="...",
|
||||
@@ -6134,6 +6147,16 @@ fn desugarcallargs(c: *checker, n: *syntax.node) void = {
|
||||
prev = a;
|
||||
a = nexta;
|
||||
};
|
||||
// Arity, missing side — a regular param left over after the
|
||||
// args ran out (a leftover TK_ELLIPSIS or FFI "..." is a legal
|
||||
// zero-arg variadic tail). Mirror cstage `not enough arguments`.
|
||||
if (param != nil) { if (param.kind == syntax.nkind.N_PARAM) {
|
||||
if (param.op != syntax.tkind.TK_ELLIPSIS
|
||||
&& !syntax.streq(param.str, "...")) {
|
||||
cerr("error: not enough arguments\n");
|
||||
c.errs += 1;
|
||||
};
|
||||
}; };
|
||||
};
|
||||
|
||||
// checkassign — #258 at the assignment context. wwstage runs no other
|
||||
|
||||
Reference in New Issue
Block a user