Files
scriptc/tests/diagnostics/arguments-length-self-call.ts
T
Chris Tate e4dc0900d7 Fence arguments.length in function expressions that call themselves by name
A function expression stored in a function type with more parameters
folds `arguments.length` to that type's parameter count, the count every
call through the slot passes. A named expression that calls itself
through its own name passes only its declared parameters there, so no
constant answers both calls. Such a read now reports SC1090 with the
reason, and expressions that do not refer to their own name keep the
fold.
2026-10-22 10:09:08 -05:00

9 lines
426 B
TypeScript

// `arguments.length` in a function expression stored in a slot with more
// parameters counts that slot's arguments, but a call through the
// expression's own name passes only the declared ones: no constant answers
// both, so the read fences.
const count: (a: number, b: number) => number = function self(a: number): number {
return a > 0 ? self(a - 1) + arguments.length : arguments.length;
};
console.log(count(2, 0));