Skip to content

fix(semantics): isolate parameter expression environments - #775

Closed
rudycelekli wants to merge 1 commit into
morluto:mainfrom
rudycelekli:fix/parameter-default-lexical-environment-20261006
Closed

rudycelekli wants to merge 1 commit into
morluto:mainfrom
rudycelekli:fix/parameter-default-lexical-environment-20261006

Conversation

@rudycelekli

Copy link
Copy Markdown

Summary

Keep default-parameter expressions and computed destructuring keys outside the function body var environment. The analyzer currently resolves a call in a default expression to a body-local declaration that is not visible there at runtime.

Functions with parameter expressions now have a separate body environment. Expression-free simple, destructured, and rest parameters retain their existing var environment. This is a lexical call-target correction; optional parameter values and cross-function argument values remain conservative.

Native reproduction

For function run(value = helper()) { function helper() { return 'INNER'; } return value; }, with an outer helper returning OUTER, Node returns OUTER. The built public analyzer previously linked the default call to the inner helper. It now links that call to the outer helper and retains the body call's inner target.

Native/public CLI controls cover a body declaration, body const, and arrow function. Checked regressions also cover body var, methods, default closures, computed/nested destructuring, parameter references, and expression-free var/parameter identity.

Verification

  • 217 focused semantic/graph and public CLI tests pass across 11 files.
  • npm run build:cached, npm run check, and npm run check:fast pass (125 lint warnings, zero errors).
  • Both this patch and the independent named function-expression fix combine cleanly: 231 tests across 14 files pass, with a native default-name/body-shadow control.
  • Signed DCO head: 3a0405ce88ebff8586c67e6024d5c63b14745b59.

No schema, provider, or packaged-artifact behavior changes are claimed. This does not claim complete ECMAScript binding or value analysis. Codex assisted on behalf of @rudycelekli with reproduction, implementation, tests, and an independent source review. Hosted CI runs separately.

@rudycelekli

Copy link
Copy Markdown
Author

CI status: the Windows native-controls job was cancelled while preparing the cross compiler, before the build/test steps ran. The two dependent package/Windows checks were skipped; the other fifteen checks passed.

I attempted to rerun the incomplete workflow (37509963582), but GitHub returned “Must have admin rights to Repository.” An upstream administrator needs to rerun it. The focused semantic tests and required local checks passed; I am treating hosted CI as incomplete until the Windows lane finishes.

@morluto

morluto commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Reviewed: correct isolation of default-param/computed-key expressions from the body var environment. Trigger covers AssignmentPattern, RestElement/ArrayPattern, ObjectPattern computed keys, and methods; expression-free params keep the single env. Param-reference and argument-flow preservation is pinned in both directions plus CLI acceptance. APPROVE.

Non-blocking suggestion: consider pinning the duplicate-binding shape (e.g. function run(value = helper()) { var value; } yields param-outer/var-inner with body refs resolving inner) to lock the split against future simplification.

@morluto morluto closed this in #776 Oct 6, 2026
@morluto

morluto commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Review — APPROVE

Summary

Isolates default-parameter expressions and computed destructuring keys from the function body var environment. When any parameter contains an expression, the body BlockStatement becomes its own function-kind scope, so a call in a default (e.g. helper() in function run(value = helper())) resolves to the outer helper rather than a body-local declaration.

Verification

  • Trigger parameterHasExpressions covers AssignmentPattern, TSParameterProperty, RestElement/ArrayPattern (incl. hole guard), and ObjectPattern (property.computed || recurse(value)).
  • Expression-free params keep the existing single var environment (pinned by test); concise-body arrows correctly unaffected.
  • Parent-chain wiring preserves legitimate upward references: first references (default + body) map to the same param binding and argumentFlows survive the split.
  • Pure domain change, no contract change; optional values stay unresolved, no identities guessed.
  • CI: all completed checks SUCCESS.

Suggestion (non-blocking)

  • Consider pinning the duplicate-binding shape, e.g. function run(value = helper()) { var value; ... } yields param-outer / var-inner with body refs resolving inner, to lock the split against a future simplification back to one environment.

@rudycelekli

Copy link
Copy Markdown
Author

Thanks for the review. I prepared the suggested duplicate-binding control, including a second parameter default referencing the parameter binding; 42 focused tests and the required checks passed. I noticed this PR was subsequently closed without a merge, and current main still has the original parameter/body environment behavior. Was that closure intentional, or would you like the control added and this PR reopened? I have left it closed while clarifying.

},
);

it("retains parameter references and argument flow across the body environment", () => {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion (non-blocking): consider pinning the duplicate-binding shape here, e.g. function run(value = helper()) { var value; ... } yields param-outer / var-inner with body refs resolving inner. Locks the split against a future simplification back to one environment.

@morluto

morluto commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Thanks, @rudycelekli, for your work on “fix(semantics): isolate parameter expression environments.” I appreciate your contribution to REA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants