Fix ReturnBinaryOrToEarlyReturnRector mixing up returned nodes of array, hook into StmtsAwareInterface instead to keep next Rector rules updated#4476
Merged
TomasVotruba merged 2 commits intomainfrom Jul 11, 2023
Conversation
baab46c to
791536f
Compare
Member
Author
|
Let's see if this helps with the build :) |
Member
|
@TomasVotruba thank you 🙏 |
Member
Author
|
Thanks! That was a journey deep into AST world 😆 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
System error: "Trying to replace statement (Stmt_Return) with expression (Expr_BooleanNot). Are you missing a Stmt_Expression wrapper?rector#8044After 3 hours of debugging, I've found out the issue is in 1 node being replaced by many nodes. Espcially
returnwith manyifs. Lot of rules hook into theIf_node then and php-parser incorrectly resolved original position. Instead of working with new array, it still operates with original tree. Then the node tree gets messed up as some rules work with one node and another with array of many nodes.This is trail of making the rule work with parent node -
StmtsAwareInterface, to always provide child node with final rules.In short: replace one node with array of nodes only on a stmts aware. Better do not change node structure from 1 to many :)
Let's see how it works, we might want to update few more rules in the future.