Repository navigation
Description
Parent: #904
Related: #928 (found while adversarially reviewing that fix), #929 (the opposite direction: valid code rejected)
Invalid programs accepted
Every row below was executed against node and zig-js, not read off the code. node rejects each as a SyntaxError; zig-js parses each successfully (OK, or a later runtime error such as ReferenceError — either way the parser accepted it).
All 20 are pre-existing. A test262 binary built from the parser before #928 gives the same result on every one; #928 neither introduced nor fixed any of them.
The 15 test262 subtrees gated for #928 (11,890 tests, 0 fail) do not exercise these shapes, so a green corpus says nothing about them.
1. Function bodies the scope walk never reaches — 13 cases
The same program inside a function body is checked if that function is a declaration, and silently accepted if it is almost anything else:
| program | node | zig-js |
|---|---|---|
(function(){ let x; var x; })(); |
SyntaxError | accepts |
g0(function(){ let x; var x; }); |
SyntaxError | accepts |
({ m(){ let x; var x; } }); |
SyntaxError | accepts |
xx = () => { let y; var y; }; |
SyntaxError | accepts |
function h(){ return function(){ let x; var x; } } |
SyntaxError | accepts |
var a = 1, b = function(){ let x; var x; }; |
SyntaxError | accepts |
let a2 = 1, b2 = class { m(){ let x; var x; } }; |
SyntaxError | accepts |
for (var i = function(){ let x; var x; };;) break; |
SyntaxError | accepts |
[function(){ let z; var z; }]; |
SyntaxError | accepts |
class K { x = function(){ let z; var z; }; } |
SyntaxError | accepts |
let {a = function(){ let z; var z; }} = {}; |
SyntaxError | accepts |
new function(){ let x; var x; }; |
SyntaxError | accepts |
function f2(a = function(){ let x; var x; }){} |
SyntaxError | accepts |
Cause: recurseScope descends an expr_stmt only when the expression is a function or class, and a var_decl initializer only for single declarators. It never follows call arguments, object/array literals, assignments, return values, class field initializers, default parameter values, or the initializers inside a declaration group, destructuring declaration or for head. #928 preserved that reach exactly rather than widening it inside a performance change.
2. with bodies are never walked — 2 cases
| program | node | zig-js |
|---|---|---|
{ let x; with ({}) { var x; } } |
SyntaxError | accepts |
with ({}) { let y; var y; } |
SyntaxError | accepts |
Cause: neither the scope walk nor collectVarNames has a .with_stmt arm.
3. Labelled function declarations are not counted — 3 cases
| program | node | zig-js |
|---|---|---|
let g; lbl: function g(){} |
SyntaxError | accepts |
function g2(){ let f; lbl: function f(){} } |
SyntaxError | accepts |
{ let f; lbl: function f(){} } |
SyntaxError | accepts |
Cause: only a direct func_decl statement is checked as a var-scoped name, and the lexical seen set has no labeled_stmt arm, so a labelled function is invisible to both sides.
4. Strict duplicate block functions checked with sloppy strictness — 2 cases
| program | node | zig-js |
|---|---|---|
function s(){ "use strict"; { function g(){} function g(){} } } |
SyntaxError | accepts |
class C2 { m(){ { function g(){} function g(){} } } } |
SyntaxError | accepts |
Cause (from reading, consistent with the executed result): addDecl decides rigidity from self.strict, but this check runs after the function body has been parsed, by which point parseFnBody's defer has already restored the enclosing sloppy strictness. Two block-level functions in strict code are then treated as Annex B.3.3 plain duplicates. Top-level strict code and class static blocks are checked during parsing and are unaffected.
Not verified by execution
Readings from the same review that I could not run, because test262 --eval has no module mode. Listed so they are not lost, and not claimed as confirmed:
- module top-level lexical names are never compared with nested vars —
let x; { var x; }as a module; export_declis not walked —export function f(){ let x; var x; }.
Suggested order
Each family is a separate root cause and can land separately. For each: pin the cases above as a parser test confirmed against node first, then change the walk, then re-run the #928 gate subtrees and the #928 frozen workloads — family 1 widens the walk's reach, so it is exactly the kind of change that could reintroduce the quadratic #928 removed.
Activity
fix(parser): scope class static block functions as var declarations
glennmichael123 commentedon Sep 16, 2026
Additional executed evidence for family 4 (strict duplicate block functions), found while gating #929: the
switch-case form is affected too, not just plain blocks.function g(){ "use strict"; { function f(){} function f(){} } }function g(){ "use strict"; switch (0) { case 0: function f(){} case 1: function f(){} } }Both fail identically with the parsers before and after #929, so they are not caused by it. The switch form fits the diagnosis already given: the whole switch is checked as one block scope, and
addDeclreads rigidity fromself.strictafter the body parse has restored it.A related but separate bug surfaced in the same corpus and is filed as #931: destructuring catch parameters wrongly allow a same-named
var.fix(parser): reject a var reusing a destructuring catch parameter
glennmichael123 commentedon Sep 16, 2026
Two more executed cases for the reach families here, surfaced while fixing #931. Both are now rejected-by-rule but unreached: the #931 check is correct, but the lexical walk never visits these positions.
(function(){ try {} catch ([e]) { var e; } })()try {} catch ([e]) { with ({}) { var e; } }withbodySince #931 moved a check into the walk, fixing families 1 and 2 now widens the coverage of that check too, not only of the lexical/var early error — worth including both in any pinned test for those families.
fix(parser): preserve strictness in scope checks (#930)
chrisbbreuer commentedon Sep 21, 2026
Family 4 is fixed and pushed in
3e792eed(fix(parser): preserve strictness in scope checks (#930)).The scope walk runs after
parseFnBodyhas restored the enclosing mode. It now temporarily usesFunctionNode.is_strictwhile checking that body, so duplicate plain functions in strict blocks andswitchcase blocks reject, while sloppy Annex B.3.3 duplicates remain valid. The mode is restored before checking sibling functions.Evidence:
switchprograms: pre-fixOK 1; afterERR UnexpectedToken; Node 24.18 rejects both with SyntaxError;switchcases, plus sloppy and restoration controls;Families 1–3 remain open on this issue.
fix(parser): count labelled function declarations (#930)
chrisbbreuer commentedon Sep 21, 2026
Family 3 is fixed and pushed in
0a2c1cbb(fix(parser): count labelled function declarations (#930)).The declaration collector now peels an Annex B.3.2 label chain to its FunctionDeclaration. The name follows the containing statement-list rules: var-scoped in Script/FunctionBody lists and lexical in Block/CaseBlock lists. Catch-parameter lexical conflicts use the same classification.
Evidence:
var/class conflicts, nested labels, CaseBlock conflicts, and a destructuring-catch conflict now reject as Node 24.18 does;varcoexistence and sloppy duplicate block/switch functions;Families 1 and 2 remain open.
fix(parser): traverse with bodies in declaration checks (#930)
chrisbbreuer commentedon Sep 21, 2026
Family 2 is fixed and pushed in
ada64fff(fix(parser): traverse with bodies in declaration checks (#930)).Both declaration walkers now descend through a
withstatement's body. The object environment changes runtime lookup but is not a lexical or var declaration boundary. This also extends #931's destructuring-catch conflict check throughwith, as requested.Evidence:
OK undefined; afterERR UnexpectedToken; Node 24.18 rejects all three;Family 1 remains open.
perf(parser): check lexical for heads by declaration order, not by re…
fix(parser): check every function body as it is parsed (#930)
test(parser): pin the other declaration checks in expression-nested f…
glennmichael123 commentedon Sep 21, 2026
Family 1 is fixed and pushed in bb48fb2 (
fix(parser): check every function body as it is parsed (#930)), with the shapes from the #931 comment above pinned in f2bafeb.Change. Every function body is now checked once, the moment
parseFnBodyor a block-bodied arrow finishes it, against a fresh scope. A function body is a fresh var scope, so nothing outside it can take part in its conflicts. The check also runs with the body's own strictness still in force, which the family 4 fix previously had to restore by hand. The post-parse scope walk no longer descends into functions or class members at all. Keeping that descent next to the per-body check would walk every nested body once per enclosing body, which is #928's quadratic.Executed, Debug f4100cc (before) vs bb48fb2 (after), node v24.4.1 as the oracle:
`${function(){ let x; var x; }}`;({ get p(){ let x; var x; } });async () => { let x; var x; };(function(){ try {} catch ([e]) { var e; } })()(from the #931 comment)[() => { try {} catch ([e]) { var e; } }];(function(){ with ({}) { let q; var q; } })();(function(){ "use strict"; { function g(){} function g(){} } })();x = class { m(){ switch (0) { case 0: function g(){} case 1: function g(){} } } };Twelve programs node accepts are unchanged and pinned as a single case. They cover distinct names, duplicate
vars, a lexical shadow in a nested block, avarover an outer function's lexical name, sloppy Annex B duplicate block functions (an object literal method included), strict single block functions, names reused across or after sibling functions, and avarover a simple catch parameter.Growth, as #933 item 6 requires. I re-measured all 18 #926/#928 rows and item 2's function-body rows at 256–2048, using the median of 18 samples a side with the two binaries interleaved. Every row grows about x2 per doubling before and after, at the top level and inside a function; the table is in bb48fb2. One reading,
private_nested_single_innerafter at 2048, came out at 636 µs. Three repeats give 267–271 µs, x2.00–x2.01. The same row run undertaskpolicy -b(efficiency cores) gives 600–770 µs, median ~646, so that reading was the process landing on E-cores.Conformance. Debug before and after, 0 fail on both sides, identical
--diagoutput. The subtrees are test/language/statements 9,337, expressions 11,038, test/annexB 1,086, block-scope 145, function-code 217, eval-code 347, global-code 42, arguments-object 263, and test/built-ins/Function 509: 22,984 tests in all. Flips 0 cases. Parser units 215/215; focused frontend 58, runtime 17, vm 4.All four families are fixed (4: 3e792ee, 3: 0a2c1cb, 2: ada64ff, 1: bb48fb2), so I'm closing this.