Repository navigation
Description
What
docs/plans/issue-2088.md's escape analysis (condition 4 of computeObjectLiteralSiteEscapes, WU-2) resolves an identifier-valued pair or shorthand object-literal property to the same-file function it names via resolveIdentifierValueThisReference → findTopLevelFunctionNodeByName, which only ever searches the module root's direct children.
Round 10 (PR #2612) fixed a soundness bug (Greptile-flagged as "Shadowed handler resolves incorrectly"): when a function- or block-scoped object literal uses an identifier/shorthand property whose name is also declared at module level, findTopLevelFunctionNodeByName resolved to that unrelated module-level declaration with full confidence — even though the name is actually shadowed, at the object literal's own lexical position, by a closer, non-module declaration. A this-using shadowing handler could consequently be classified this-free, making T1 exclusive with no evidence for an invoked sibling property and reporting it dead.
The fix makes resolveIdentifierValueThisReference check findDeclaringScopeNode(objectNode, name) first and fail safe (treat the property as potentially this-using) whenever the name is shadowed by any scope strictly between the object literal and the module root — without attempting to resolve the identifier into that shadowing scope's own declaration and check whether that declaration itself uses this.
This closes the soundness hole, but it is strictly more conservative than necessary: a shadowing declaration that is itself genuinely this-free would, under a fuller fix, still allow T1 to fire; under this fix it does not — the site always escapes and falls back to T2 once any shadowing is detected, regardless of what the shadowing declaration's body actually contains.
Why this wasn't fixed with full resolution directly
findTopLevelFunctionNodeByName's search shape (module-level function_declaration or variable_declarator children only) cannot be reused as-is against an arbitrary block/function scope — a more general traversal would be needed, adding a second AST-search shape to a soundness-critical resolution chain this same plan has already found bugs in across rounds 7, 8, and 9 — and doing so identically in both the TypeScript and Rust engines. Fail-safe was chosen instead: it closes the confidently-wrong-answer hazard immediately, with no new traversal shape to get wrong a sixth time, consistent with how every other unresolved-identifier case in this function is already handled (an import, a non-function binding, or a declaration nested past the module-level-only search all already fail safe rather than attempt deeper resolution).
Suggested fix shape (not binding — decide at execute/fix time)
Generalise findTopLevelFunctionNodeByName's declaration-shape matching (a function_declaration, or a variable_declarator whose value is an arrow_function/function_expression/function) into a helper parameterised on which node's direct children to search, then call it against findDeclaringScopeNode(objectNode, name)'s result (when non-null) instead of unconditionally failing safe on it. Add a WU-10 escape-fallback case proving a shadowing declaration that is itself this-free correlates once implemented, without weakening the round-10 fail-safe default for a shadowing declaration that is not provably safe.
Where
docs/plans/issue-2088.md— WU-2'sresolveIdentifierValueThisReference(condition 4's identifier-resolution helper) and its doc comment; the round-10 essay incomputeObjectLiteralSiteEscapes's own doc comment.- Tracking issue: follow-up: receiver-type-aware invoked-property matching to reduce dead-code false negatives #2088. PR: [Plan] issue-2088: receiver-correlated invoked-property evidence for object-literal value-refs #2612.
Activity
docs: close round-10 identifier-resolution gaps in WU-2 condition 4
feat(roles): receiver-correlated invoked-property evidence for object…