Skip to content
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

File::getMethodProperties(): skip over closure use statements #421

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 29, 2024

Description

This PR improves performance of the File::getMethodProperties() method and prevents incorrect return type information for closure use clauses containing invalid variable imports in the use clause (defensive coding).

Closure use statements can only import plain variables, not properties or other more complex variables.

As things were, when such "illegal" variables were imported in a closure use, the information for the return type could get mangled.
While this would be a parse error, for the purposes of static analysis, the File::getMethodProperties() method should still handle this correctly.

This commit updates the File::getMethodProperties() method to always skip over the complete use clause, which prevents the issue and improves performance as the same time (less token walking).

Includes unit tests.

Suggested changelog entry

File::getMethodProperties(): small performance improvement & more defensive coding

@jrfnl jrfnl added this to the 3.9.1 milestone Mar 29, 2024
@jrfnl jrfnl changed the title File::getMethodProperties(): bug fix - skip over closure use statements File::getMethodProperties(): skip over closure use statements Mar 30, 2024
@jrfnl
Copy link
Member Author

jrfnl commented Mar 30, 2024

Hmm.. turns out the code sample which triggered me to look into this was actually a parse error 🤦🏻‍♀️. I do still believe the change has value, but I've updated the PR description to reflect the reality (and simplified the tests a little).

@jrfnl jrfnl force-pushed the feature/getmethodproperties-bugfix-skip-closure-use branch from 4343197 to 87fd6b8 Compare March 30, 2024 10:17
@jrfnl jrfnl modified the milestones: 3.9.1, 3.9.2 Mar 31, 2024
Copy link
Contributor

@rodrigoprimo rodrigoprimo left a comment

Choose a reason for hiding this comment

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

LGTM

This PR improves performance of the `File::getMethodProperties()` method and prevents incorrect return type information for closures `use` clauses containing invalid variable imports in the `use` clause (defensive coding).

Closure `use` statements can only import plain variables, not properties or other more complex variables.

As things were, when such "illegal" variables were imported in a closure `use`, the information for the return type could get mangled.
While this would be a parse error, for the purposes of static analysis, the `File::getMethodProperties()` method should still handle this correctly.

This commit updates the `File::getMethodProperties()` method to always skip over the complete `use` clause, which prevents the issue and improves performance as the same time (less token walking).

Includes unit tests.
@jrfnl jrfnl force-pushed the feature/getmethodproperties-bugfix-skip-closure-use branch from 87fd6b8 to 0dff1a5 Compare April 3, 2024 01:37
@jrfnl
Copy link
Member Author

jrfnl commented Apr 3, 2024

Rebased without changes, merging once the build has passed.

@jrfnl jrfnl enabled auto-merge April 3, 2024 01:38
@jrfnl jrfnl merged commit 82ad715 into master Apr 3, 2024
44 checks passed
@jrfnl jrfnl deleted the feature/getmethodproperties-bugfix-skip-closure-use branch April 3, 2024 01:56
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants