-
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
Wrong T_FN token when $this->fn #2859
Comments
@BafS You beat me to it 😀 I was working on an issue write-up for this and some more similar issues. I'll try and find the time to write it up properly and add those here hopefully by tomorrow. |
Thanks @jrfnl ! |
Related to #2523 I've tried to do an inventory of any situation I could think of for the As shown in the below table, there are a number of inconsistencies with the current tokenization of arrow functions:
In part the current tokenization is incorrect:
See: https://www.php.net/manual/en/reserved.keywords.php In part the current tokenization is unpredictable: In part the current tokenization is unexpected/makes sniffing hard: ProposalFor the same reason as This includes tokenizing This will make life easier for sniff writers as you can then count on a I've got unit tests ready for this already. @gsherwood If you agree with this proposal, I'd be happy to complete the work on fixing this. Findings
|
PR #2860 implements the proposal outlined above. |
Oh and just to bring the point home: the proposed fix will also prevent nonsensical results from the A call to array(9) {
["scope"]=>
string(6) "public"
["scope_specified"]=>
bool(false)
["return_type"]=>
string(0) ""
["return_type_token"]=>
bool(false)
["nullable_return_type"]=>
bool(false)
["is_abstract"]=>
bool(false)
["is_final"]=>
bool(false)
["is_static"]=>
bool(false)
["has_body"]=>
bool(true)
} And for |
I sure do. Thanks for the PR - I've left a couple of comments on there for testing. |
Thanks @jrfnl for the thorough research into this, and for the PR to fix it all up. |
@gsherwood I'm just happy we got it sorted as, as things were, sniffing for arrow functions was harder than it should be IMO. I hope I caught everything, but either way, the currently implemented solution should make it stable for the future. |
This commit implements the proposal as outlined in 2859#issuecomment-583695917. The `fn` keyword will now only be tokenized as `T_FN` if it really is an arrow function, in which case it will also have the additional indexes set in the token array. In all other cases - including when the keyword is used in a function declaration for a named function or method -, it will be tokenized as `T_STRING`. Includes numerous additional unit tests. Includes removing the changes made to the `File::getDeclarationName()` function and the `AbstractPatternSniff` in commit 37dda44 as those are no longer necessary. Fixes #2859 Fixed tests for #2860 Tokenizer arrow functions backfill tests: fix it ;-) Follow up on 2860. This fixes the tests. * Adds tests with mixed case `fn` keyword. * Removes a few redundant tests (weren't testing anything which wasn't covered already). * Adds a couple of tests which were missing from the data provider. * Updates the test itself to use a `$testContent` parameter to allow for the `fn` in the tests being non-lowercase. Added a few more tests for the T_FN backfill (ref #2863, #2860, #2859)
This commit implements the proposal as outlined in 2859#issuecomment-583695917. The `fn` keyword will now only be tokenized as `T_FN` if it really is an arrow function, in which case it will also have the additional indexes set in the token array. In all other cases - including when the keyword is used in a function declaration for a named function or method -, it will be tokenized as `T_STRING`. Includes numerous additional unit tests. Includes removing the changes made to the `File::getDeclarationName()` function and the `AbstractPatternSniff` in commit 37dda44 as those are no longer necessary. Fixes squizlabs#2859
Having
$xxx->fn
in the code is reported as aT_FN
, which is wrong.Example:
$this->fn
givesRelated issue: slevomat/coding-standard#896
The text was updated successfully, but these errors were encountered: