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: fix handling of "DNF look a likes" with switch/case and alternative control structure syntax #632

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Oct 16, 2024

Description

Follow up on #461, #507, #508

This commit intends to further improve the determination of whether tokens are part of a (return) type declaration which need special handling for the tokens or not.

It does more strenuous checking on any T_COLON encountered before the (potential) type, to try and determine with higher accuracy whether the colon indicates the start of a return type - in contrast to being a colon for a switch-case or a colon for an alternative syntax control structure.

Includes tests.
The tests also include a test with goto. This would currently not trigger this code as the colon is tokenized as part of the goto label, but as the intention is to change that tokenization in PHPCS 4.0 (per issue #185), the test being there should safeguard that the PHPCS 4.0 change will not cause any problems with the DNF related tokenization.

For now, this fixes the bug(s) reported in issue 630, though I think it might be good to revisit the tokenizer control flow in a future major, but as that will be so much easier once JS/CSS no longer needs to be taken into account, that's for the future.

Suggested changelog entry

"normal" parentheses were inadvertently transformed to DNF parentheses, when a function call was preceded by a switch-case / alternative syntax control structure colon.

Related issues/external references

Fixes #630

Types of changes

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

…d alternative control structure syntax

Follow up on 461, 507, 508

This commit intends to further improve the determination of whether tokens are part of a (return) type declaration which need special handling for the tokens or not.

It does more strenuous checking on any `T_COLON` encountered before the (potential) type, to try and determine with higher accuracy whether the colon indicates the start of a return type - in contrast to being a colon for a switch-case or a colon for an alternative syntax control structure.

Includes tests.
The tests also include a test with `goto`. This would currently not trigger this code as the colon is tokenized as part of the goto label, but as the intention is to change that tokenization in PHPCS 4.0 (per issue 185), the test being there should safeguard that the PHPCS 4.0 change will not cause any problems with the DNF related tokenization.

For now, this fixes the bug(s) reported in issue 630, though I think it might be good to revisit the tokenizer control flow in a future major, but as that will be so much easier once JS/CSS no longer needs to be taken into account, that's for the future.

Fixes 630
@jrfnl jrfnl added this to the 3.11.0 milestone Oct 16, 2024
@jrfnl jrfnl merged commit b1d8ff7 into master Oct 24, 2024
52 checks passed
@jrfnl jrfnl deleted the feature/630-tokenizer-php-improve-fix-dnf-types branch October 24, 2024 20:55
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.

Tokeniser issue for function call parenthesis - inside switch
1 participant