Skip to content

fix(rename): support renaming variables inside deeply nested arrows and closures#145

Open
calebdw wants to merge 1 commit into
PHPantom-dev:mainfrom
calebdw:calebdw/push-ksxkmtplqnzu
Open

fix(rename): support renaming variables inside deeply nested arrows and closures#145
calebdw wants to merge 1 commit into
PHPantom-dev:mainfrom
calebdw:calebdw/push-ksxkmtplqnzu

Conversation

@calebdw
Copy link
Copy Markdown
Contributor

@calebdw calebdw commented May 26, 2026

Summary

  • Fixed rename (and find-references) for variables captured through multiple levels of arrow functions (fn () => fn () => $var) and mixed function () use ($var) closures.
  • Root cause: collect_capture_scopes only walked downward and used innermost-scope matching for "has usage".
  • Added upward ancestor walk (skipping pure ClosureCapture sites) + lexical byte-range check for has_usage.
  • Added several new tests covering the exact reported case, deeply nested closures with use(), mixed nesting, and rename from both declaration and deep usage sites.

Fixes #143

Testing

  • All new + existing rename propagation tests pass
  • Full references test suite (62 tests) passes
  • cargo check + cargo clippy --tests -- -D warnings clean

…nd closures

- Add upward ancestor walk before collect_capture_scopes so rename/refs
  work when invoked from deep inside fn()=>fn()=> $var or mixed
  function() use() { ... } closures.
- Switch has_usage to lexical byte-range containment so intermediate
  arrow scopes in nesting chains are recognized.
- Add tests covering the reported case, deeply nested closures with use(),
  mixed closure+arrow, and both "from declaration" and "from usage" directions.
- Restore and update internal comments for accuracy.

Fixes PHPantom-dev#143
@calebdw calebdw force-pushed the calebdw/push-ksxkmtplqnzu branch from 853b111 to 71924a0 Compare May 26, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: rename does not work inside nested closure

1 participant