-
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
Generic.Formatting.MultipleStatementAlignment error with const DEFAULT #3326
Comments
I've been looking into this issue. A git bisect learns that it first surfaces with commit 2ba5393 in response to #3219. That commit, however, did not cause the issue. Rather, it exposes an underlying issue related to #3336. After The So, like #3336, this is a problem with reserved keywords being used as names in valid contexts, but still being tokenized as the reserved keyword by PHP. As discussed in #3020, the |
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.
@caseyjhol Thanks for reporting this. PR #3351 should fix this. Testing appreciated. |
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.
As per: #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.
Describe the bug
I'm getting an error when attempting to align the assignment tokens when defining constants, if one of the constants is named
DEFAULT
. It's trying to alignDEFAULT
with the array assignment token below, rather than the other statements directly below it.Code sample
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior
No reported errors.
Versions (please complete the following information):
Additional context
To clarify the issue, this throws no errors:
This also throws no errors:
The text was updated successfully, but these errors were encountered: