Skip to content
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

Tokenizer/PHP: bug fix for static typed properties with union/intersection types #78

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 11, 2023

Description

Recreation of upstream PR squizlabs/PHP_CodeSniffer#3867:

Just like the var keyword, the static keyword can also be used stand-alone with property declarations. https://3v4l.org/sbaDM

In that case, the tokenization of the | operator was not changed to T_TYPE_UNION and the & operator was not changed to T_TYPE_INTERSECTION as the static keyword can also be used in return type declarations, so was seen as part of the type declaration.

Fixed now by removing the T_STATIC token from the $allowed list before walking backwards from the operator.

Includes tests.

Note: this does mean that one test for the File::getMemberProperties() method needs to be changed, but as that was testing an illegal syntax anyway, I'm not concerned about making this change.

Suggested changelog entry

Tokenizer/PHP: union type and intersection type operators were not correctly tokenized as such for static typed properties without explicit visibility.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

@jrfnl jrfnl added this to the 3.8.0 milestone Nov 11, 2023
@jrfnl jrfnl mentioned this pull request Nov 24, 2023
7 tasks
@jrfnl jrfnl force-pushed the feature/tokenizer-php-bugfix-static-typed-props-union-intersection branch 2 times, most recently from 43982c6 to 2ea1223 Compare December 4, 2023 13:13
…ction types

Just like the `var` keyword, the `static` keyword can also be used stand-alone with property declarations.
https://3v4l.org/sbaDM

In that case, the tokenization of the `|` operator was not changed to `T_TYPE_UNION` and the `&` operator was not changed to `T_TYPE_INTERSECTION` as the `static` keyword can also be used in return type declarations, so was seen as part of the type declaration.

Fixed now by removing the `T_STATIC` token from the `$allowed` list before walking backwards from the operator.

Includes tests.

Note: this does mean that one test for the `File::getMemberProperties()` method needs to be changed, but as that was testing an illegal syntax anyway, I'm not concerned about making this change.
@jrfnl jrfnl force-pushed the feature/tokenizer-php-bugfix-static-typed-props-union-intersection branch from 2ea1223 to 6a3b638 Compare December 4, 2023 13:27
@jrfnl jrfnl merged commit 334a64f into master Dec 4, 2023
63 checks passed
@jrfnl jrfnl deleted the feature/tokenizer-php-bugfix-static-typed-props-union-intersection branch December 4, 2023 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant