-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHPCS hangs processing some nested arrow functions inside a function call #3324
Comments
The problem is this line which is causing the infinite loop in the tokenizer when an outer and inner arrow function need to share a scope closer: PHP_CodeSniffer/src/Tokenizers/PHP.php Line 2364 in 62e6e06
Adding an additional condition of I'm not sure how to solve this. @gsherwood may have a better idea and at least it's now clear where the problem lies. |
This is obviously not real code, and I haven't looked into this yet, but the issue can be reproduced on this snippet: $foo = foo(fn() => fn() => bar() === true); |
I have confirmed that reverting the fix for #3284 does fix this issue, but only because the inner arrow function is being tokenized incorrectly with that old code. For this sample: $foo = foo(fn() => fn() => bar() === true); The old code see the scope closer of the inner arrow function as the closing parenthesis of the |
I have a potential fix for this that I'm playing around with. It basically just uses the scope closer of any nested arrow function it finds, as long as it's not inside a ternary. It's assuming the closer for that arrow function was set correctly. It leaves the match expression code alone though, so there is an exception to that rule. |
I've pushed a fix for this to master only. I'd appreciate anyone's opinion on this, and additional test cases to either prove or disprove the fix. I'll finish picking this into 4.0 once I'm more confident that the issue is fixed. |
Hi, This is real PHP code, I just stripped out Psalm annotations, use statements and renamed methods. I'm unable to provide the real code for now on because this is a complete refactoring depending on another library, but if you want to see the previous version of this, it's here (that version doesn't make any issue with PHP CS). |
Sorry, that's not what I meant. I meant that my one-line code snippet in the comment is not real code, but the smallest possible code I could use to reproduce the issue. |
Ooh ok sorry :) |
Using the dev version and it seems to work fine. Thanks! |
@drupol Thanks a lot for testing that out. I have merged this into the 4.0 branch now, so I'll close this issue as resolved, but please do post again if you find another place this fails before it is released in version 3.6.1. |
Describe the bug
Hello,
I'm using PHP CS in a project and I'm doing experimentation in a local branch.
While testing some stuff, I run from time to time PHP CS with the
PSR12
standard.However, for some reason, it hangs on a file. I streamlined the file to the strict minimum for this issue:
Code sample
To reproduce
Expected behavior
I expect to have a report.
Versions (please complete the following information):
Linux
7.4.16
3.6
anddev-master
PSR12
The text was updated successfully, but these errors were encountered: