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
[Downgrade] A 2nd rule should modify the output from a previous rule in the set, but it doesn't happen #5962
Comments
This is not possible, because of how php-parser traverses nodes. From top to bottom. You can change the rule order: But if there is a class node with method node in it, all the class rules will be procesed first. Then all the rules for method node. |
Hmmmm... Is there some way to solve this issue? For instance, what about having the 2 rules in two different sets? Would that solve the issue?
Or otherwise, how? |
This should be handled in the rule itself, independent on the other. E.g. If PHP 8 unin typed property is downgraded, there should be different results depending on target php version:
Upgrades work the same way |
Hmmm then the logic would be completely mixed up: checking if the return type is Also, if somebody wants to only downgrade the covariant types and execute the rule directly, not within a set, then this rule would produce a bug. I'll fix it with a hack instead: I'll run Then, I will enhance testing the downgrade will fail as I explain here: GatoGraphQL/GatoGraphQL#544, so that if this same problem happens again with some other file, the test will fail, and then I manually fix it again. |
I'm not sure if DowngradeSelfTypeDeclarationRector should remove Edit: I think |
Bug Report
Package
symfony/cache
has filevendor/symfony/cache/CacheItem.php
, with this content (here):The interface
ItemInterface
has this content (here):The downgrade set for PHP 7.4 has these 2 rules, in this same order:
When downgrading
CacheItem.php
, functiontag
should be modified twice:DowngradeCovariantReturnTypeRector
must first transform the return type, fromItemInterface
toself
DowngradeSelfTypeDeclarationRector
should then remove theself
return typeBut the second step is not happening. As a consequence, after running the downgrade, function
tag
returnsself
, which is not accepted for PHP 7.3.Minimal PHP Code Causing Issue
I tried to recreate the problem here, but the output is different:
https://getrector.org/demo/0d1b5ce4-c1a3-4fb8-bc3f-1fbe982f6e90
The text was updated successfully, but these errors were encountered: