Skip to content

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
tv-fixup
Jul 11, 2023
Merged

Fix ReturnBinaryOrToEarlyReturnRector mixing up returned nodes of array, hook into StmtsAwareInterface instead to keep next Rector rules updated#4476
TomasVotruba merged 2 commits intomainfrom
tv-fixup

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

@TomasVotruba TomasVotruba commented Jul 11, 2023

After 3 hours of debugging, I've found out the issue is in 1 node being replaced by many nodes. Espcially return with many ifs. Lot of rules hook into the If_ 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.

@TomasVotruba TomasVotruba force-pushed the tv-fixup branch 11 times, most recently from baab46c to 791536f Compare July 11, 2023 15:26
@TomasVotruba TomasVotruba changed the title tv fixup Fix ReturnBinaryOrToEarlyReturnRector mixing up returned nodes of array, hook into StmtsAwareInterface instead to keep next Rector rules updated Jul 11, 2023
@TomasVotruba TomasVotruba enabled auto-merge (squash) July 11, 2023 15:31
@TomasVotruba
Copy link
Copy Markdown
Member Author

Let's see if this helps with the build :)

@TomasVotruba TomasVotruba merged commit 26a368c into main Jul 11, 2023
@TomasVotruba TomasVotruba deleted the tv-fixup branch July 11, 2023 15:31
@samsonasik
Copy link
Copy Markdown
Member

@TomasVotruba thank you 🙏

@TomasVotruba
Copy link
Copy Markdown
Member Author

Thanks!

That was a journey deep into AST world 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

System error: "Trying to replace statement (Stmt_Return) with expression (Expr_BooleanNot). Are you missing a Stmt_Expression wrapper?

2 participants