Skip to content

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jul 14, 2022

Originally reported in sirbrillig/phpcs-variable-analysis#263.

When the short list syntax would be used as the first contents within a control structure without braces, the square brackets would be tokenized as plain square brackets, not as short array brackets.

if ( true ) [ $a ] = [ 'hi' ]; // The first `[` in this line was tokenized incorrectly. return $a ?? '';

Fixed now by checking whether the preceding parenthesis closer has an owner and if that owner could be a scope owner.

Includes unit tests.
Includes updating the data providers to use named data sets to allow for easier debugging.

…thout braces Originally reported in sirbrillig/phpcs-variable-analysis 263. When the short list syntax would be used as the first contents within a control structure without braces, the square brackets would be tokenized as plain square brackets, not as short array brackets. ```php if ( true ) [ $a ] = [ 'hi' ]; // The first `[` in this line was tokenized incorrectly. return $a ?? ''; ``` Fixed now by checking whether the preceding parenthesis closer has an owner and if that owner could be a scope owner. Includes unit tests. Includes updating the data providers to use named data sets to allow for easier debugging.
sirbrillig added a commit to sirbrillig/phpcs-variable-analysis that referenced this pull request Aug 12, 2022
sirbrillig added a commit to sirbrillig/phpcs-variable-analysis that referenced this pull request Aug 13, 2022
* Add tests for inline if list destructuring * Support treating T_OPEN_SQUARE_BRACKET as a list opener * Add test for foreach with list destructure * Better differentiate between list destructuring and array access * Use the same technique for finding list assignments as phpcs might See squizlabs/PHP_CodeSniffer#3632
@gsherwood gsherwood added this to the 3.7.2 milestone Sep 15, 2022
@gsherwood gsherwood changed the title Tokenizer/PHP: bug fix for short list tokens in control structures without braces Short list not tokenized correctly in control structures without braces Sep 15, 2022
gsherwood added a commit that referenced this pull request Sep 15, 2022
@gsherwood gsherwood merged commit 5a85210 into squizlabs:master Sep 15, 2022
@gsherwood
Copy link
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants