Skip to content

Support nested arrow functions #334

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Conversation

sirbrillig
Copy link
Owner

The way I find the scope opener for an arrow function is by searching backwards for a fn token from the place a variable is used if that variable might be within an arrow function. However, if there's another nested arrow function before the actual scope opener we want, this will result in a false positive and report the incorrect scope.

In this PR, we add a condition to the algorithm which searches backwards for the fn token: if it finds an arrow function scope close token before it finds a scope opener, then we move back to the start of that scope before continuing to search backwards.

Fixes #329

@sirbrillig sirbrillig force-pushed the support-nested-arrow-functions branch from 124cc5f to 8d6ab7c Compare November 18, 2024 01:43
@sirbrillig
Copy link
Owner Author

The failing tests are just a psalm error (#335) and are unrelated to this PR.

@sirbrillig sirbrillig merged commit b1d7c85 into 2.x Nov 18, 2024
54 of 56 checks passed
@sirbrillig sirbrillig deleted the support-nested-arrow-functions branch November 18, 2024 02:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested fat arrow closures cause false positive for UndefinedVariable
1 participant