Skip to content

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

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-record-change-on-inplace-mutation
Oct 23, 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 a branch. With the rector-src engine change in rectorphp/rector-src#8791, a pass that records no change skips the format-preserving print, so the in-place mutation is dropped and no longer applied.

Fix: return the already-mutated node (or report via the method return value) so the change is recorded. Output is identical - only the return value changes.

  • DowngradeTrailingCommasInParamUseRector: a closure with a trailing comma in its use list but no params ran processUses() (which removes the comma via the token stream) but then returned the result of processParams(), which is null when there are no params. Track a hasChanged flag and return the node when either use or param list was cleaned.
  • DowngradeArbitraryExpressionsSupportRector: refactorAssign() removes redundant parentheses around an allowed new/instanceof class by setting ORIGINAL_NODE to null, then continues and falls through to return null. Track a hasChanged flag and return [$expression] when parentheses were removed in place.

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

@TomasVotruba
TomasVotruba merged commit 05c5b7f into main Oct 23, 2026
9 checks passed
@TomasVotruba
TomasVotruba deleted the tv-record-change-on-inplace-mutation branch October 23, 2026 23:20
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