Skip to content

[CodeQuality] Skip trailing comment after return in WillReturnCallbackFallbackToReturnFalseRector - #800

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-willreturncallback-trailing-comment
Oct 13, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
fix-willreturncallback-trailing-comment

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9929

When return true; is followed by a trailing comment, PHP-Parser turns the comment into a trailing Nop statement, so it becomes the closure's last statement. The rule only checked the raw last statement for Return_, missed it, and wrongly appended a return false; fallback after an already-terminating return.

Fix skips trailing Nop statements before checking whether the closure already ends with a return.

Before:

return true; // Exit loop immediately
+return false;

Added a skip fixture reproducing the issue.

@TomasVotruba
TomasVotruba merged commit 8c960f3 into main Oct 13, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the fix-willreturncallback-trailing-comment branch October 13, 2026 20:56
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.

WillReturnCallbackFallbackToReturnFalseRector incorrectly changes return true; // comment to return false;

1 participant