Spec issues & errata · defect of the text · docs/spec-issues/63-annexb-replacing-and-b33.md
63. Annex B.3.2 type errors (Early Errors for _func_, Contains on Parse Nodes), §B.3.3 synthetic blocks, and §B.1.1 comment ambiguity
- Location
- §10.2.11 FunctionDeclarationInstantiation (
#sec-functiondeclarationinstantiation), §16.1.7 GlobalDeclarationInstantiation (#sec-globaldeclarationinstantiation), and §19.2.1.4 EvalDeclarationInstantiation (#sec-evaldeclarationinstantiation); §B.3.3 FunctionDeclarations in IfStatement Statement Clauses (#sec-functiondeclarations-in-ifstatement-statement-clauses); §B.1.1 HTML-like Comments (#sec-html-like-comments). - Kind
- type errors in normative Annex B steps, undefined synthetic AST nodes, and a lexical trivia ambiguity.
- Model erratum
AnnexBReplacingAndB33, baked-in SpecTec reading test262 (@ph-annexb-replacingand@ph-containsinspec/spectec/clauses/Helpers.spectec,asIfSourceinlean/Ecma/Ops/Parse.lean,LinEarly.linTreeinlean/Ecma/Lower/LinEarly.lean, andTriviaEleminspec/spectec/prose/04-derives.spectec).- Upstream
- Checked 2026-11-19: none found (searched for "Early Errors for func" and "synthetic |BlockStatement|").
- On this site
AnnexBReplacingAndB33on Spec issues & errata (defect of the text; SpecTec bakes in the test262 reading)
Text
§10.2.11 (FunctionDeclarationInstantiation):
If replacing the FunctionDeclaration funcDecl with a VariableStatement that has funcName as a BindingIdentifier would not produce any Early Errors for func and paramNames does not contain funcName, then
§B.3.3:
This production only applies when parsing non-strict code. Source text matched by this production is processed as if each matching occurrence of FunctionDeclaration[?Yield, ?Await, ~Default] was the sole StatementListItem of a BlockStatement occupying that position in the source text.
§B.1.1:
MultiLineComment ::
/*FirstCommentLine? LineTerminator MultiLineCommentChars?*/HTMLCloseComment?
Problem
- Type errors in §B.3.2's hoisting condition.
FunctionDeclarationInstantiationtests "Early Errors for func", where_func_is a Function Object rather than the Parse Node_code_; and all three B.3.2 clauses write "code Contains x is true" where_x_is a Parse Node (|Block|,|CaseClause|, or|DefaultClause|), whereas §8.5.1Containsonly accepts a grammar symbol! SpecTec's@ph-annexb-replacingsplices"var " + _F_ + ";"into the root parse's source text and reparses under$GoalSymbolOf, whileNodes.instanceOfwidensContainsto test Parse Node identity. - Undefined synthetic
|BlockStatement|in §B.3.3. §5.1.2 defines Parse Nodes only as parse-tree nodes of source text, leaving §B.3.3's "synthetic |BlockStatement|" without AST parentage or SDO rows. SpecTec splices{and}around childFunctionDeclarationspans (asIfSource) and redirects early errors (including inside reparsed covers viaLinEarly.linTree) and SDOs through$CoveredBy(|IfStatement|, node). - Ambiguous
MultiLineCommentin §B.1.1. Because §B.1.1 extends §12.4'sMultiLineCommentand makesHTMLCloseComment?optional, every multi-line comment with a newline and no-->(/*a\nb*/) has two lexical CFG derivations (unobservable in prose since comments are discarded with no SDOs, but relevant when checking lexical derivation uniqueness); SpecTec existentially quantifies trivia trees inScanssoParseLaws.completeholds.
Examples
function g(x) {
{ function f() { return 1; } }
let y = 0;
{ function y() { return 2; } }
if (true) function h() { return 3; }
return [typeof f, y, typeof h].join(",");
}
print(g(0));
g(0) on a web-browser host |
|
|---|---|
| literal §B.3.2 / §B.3.3 | undefined (Early Errors on Function Object _func_, Contains on Parse Node _x_, undefined synthetic BlockStatement) |
| V8, SpiderMonkey, JavaScriptCore | "function,0,function" |
formal model (--web-browser, test262 reading) |
"function,0,function" |
Proposed wording
In FunctionDeclarationInstantiation replace _func_ with _code_ (and state outer lexical-binding collision directly
instead of AST replacement + Contains on a Parse Node); in §B.3.3 give explicit Early Error and SDO rules for the four
IfStatement productions; and in §B.1.1 remove ? from HTMLCloseComment? on the extended MultiLineComment rule.
test262
annexB/language/function-code/ and annexB/language/statements/if/ test §B.3.2 block hoisting and §B.3.3 if
functions across function, global, and eval scopes.