Skip to content

Return node when node mutated in place, so change is recorded - #539

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-record-change-on-inplace-mutation
Oct 24, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-record-change-on-inplace-mutation

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Two rules mutate the AST in place and then return null on the mutating branch. With the rector-src engine change in rectorphp/rector-src#8791, a pass that records no change skips the format-preserving print, so these in-place mutations are now dropped from output. The fix returns the already-mutated node so the change is reported through the refactor() return value. Output is unchanged; only the return value changes.

Rules fixed:

  • ArrayMapOnCollectionToArrayRector - the array_filter branch called refactorArrayFilter() (which rewrites the first arg in place) but discarded its return and fell through to return null. Now returns the result.
  • CollectionDocblockGenericTypeRector - adds a generic @return tag and calls updateRefactoredNodeWithPhpDocInfo() on the node, then returned null. Now returns the mutated node.

Tested green against both rector-src main and the rectorphp/rector-src#8791 branch (306 tests).

@TomasVotruba
TomasVotruba merged commit ae86242 into main Oct 24, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the tv-record-change-on-inplace-mutation branch October 24, 2026 09:17
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.

1 participant