Tokenizer/PHP: fix tokenization of the default keyword#3351
Merged
gsherwood merged 3 commits intosquizlabs:masterfrom Jun 30, 2021
Merged
Conversation
.. safeguarding the tokenizer fix which should prevent the issue as reported in 3326.
As per: squizlabs#3326 (comment) > After `PHP::tokenize()`, the `DEFAULT` is still tokenized as `T_DEFAULT`. This causes the `Tokenizer::recurseScopeMap()` to assign it as the `scope_opener` to the `;` semi-colon at the end of the constant declaration, with the class close curly brace being set as the `scope_closer`. > In the `PHP::processAdditional()` method, the `DEFAULT` is subsequently retokenized to `T_STRING` as it is preceded by a `const` keyword, but that is too late. > > The `scope_opener` being set on the semi-colon is what is causing the errors to be displayed for the above code sample. The commit fixes this by: 1. Abstracting the list of `T_STRING` contexts out to a class property. 2. Using the list from the property in all places in the `Tokenizer\PHP` class where keyword tokens are (potentially) being re-tokenized to `T_STRING`, including in the `T_DEFAULT` tokenization code which was added to address the PHP 8.0 `match` expressions. Note: the issue was not introduced by `match` related code, however, that code being there does make it relatively easy now to fix this particular case. While this doesn't address 3336 yes, it is a step towards addressing it and will sort out one of the most common causes for bugs.
a2890a7 to
0d5663c
Compare
Contributor
Author
|
Rebased to get round merge conflict related to #3340 having been merged. |
gsherwood
added a commit
that referenced
this pull request
Jun 30, 2021
Member
|
Thanks. Sorry I didn't notice |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generic/MultipleStatementAlignment: add extra tests
.. safeguarding the tokenizer fix which should prevent the issue as reported in #3326.
Tests: add extra tests for the default keyword tokenization
Tokenizer/PHP: fix tokenization of the default keyword
As per: #3326 (comment)
The commit fixes this by:
T_STRINGcontexts out to a class property.Tokenizer\PHPclass where keyword tokens are (potentially) being re-tokenized toT_STRING, including in theT_DEFAULTtokenization code which was added to address the PHP 8.0matchexpressions.Note: the issue was not introduced by the
matchrelated code, however, that code being there does make it relatively easy now to fix this particular case.While this doesn't address #3336 yet, it is a step towards addressing it and will sort out one of the most common causes for bugs.
Fixes #3326
Closes #3340 as superseded