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