Skip to content

Arrow Functions and compact method cause false positive for UndefinedVariable bug #330

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

Closed
yokozawa0701 opened this issue Nov 16, 2024 · 2 comments · Fixed by #339
Closed
Labels

Comments

@yokozawa0701
Copy link

yokozawa0701 commented Nov 16, 2024

Here's a simple example that generates UndefinedVariable for using the Arrow Functions and compact method.

$something = fn ($arg) => compact('arg');  // Unused function parameter $arg. (VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable) 

I am using v2.11.19.
Thank you.

@sirbrillig sirbrillig added the bug label Nov 17, 2024
@sirbrillig
Copy link
Owner

sirbrillig commented Nov 30, 2024

Good find. I think this is happening because processCompact() calls findVariableScope() which has a special case for arrow function variables but needs the name of the variable itself, and we don't pass that (there could be many). Working on how to handle that case.

@sirbrillig
Copy link
Owner

This should be fixed by #339

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants