Skip to content

[NodeAnalyzer] Treat trailing comment and infinite loop as terminating in last block stmts - #8472

Closed
TomasVotruba wants to merge 1 commit into
mainfrom
terminated-analyzer-trailing-comment-and-infinite-loop
Closed

[NodeAnalyzer] Treat trailing comment and infinite loop as terminating in last block stmts#8472
TomasVotruba wants to merge 1 commit into
mainfrom
terminated-analyzer-trailing-comment-and-infinite-loop

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes the ConsoleExecuteReturnIntRector false positive reported in rectorphp/rector#9897.

TerminatedNodeAnalyzer::isTerminatedInLastStmts() only accepted a Return_ or an exit/throw expression as the last statement of a block. Two cases slipped through and made a fully-terminated try/catch look like it falls through:

  • a trailing comment at the end of a block is parsed as a Nop stmt, hiding the real last return
  • a while (true) / do/for infinite loop with no break at the end of a block never falls through, but was not recognized

Both now report the block as terminated, so no unreachable return/statement is appended after such a try/catch.

Covered with two RemoveUnreachableStatementRector fixtures (comment in catch, infinite while in try).

@TomasVotruba
TomasVotruba force-pushed the terminated-analyzer-trailing-comment-and-infinite-loop branch from d852c9b to 0398dc7 Compare September 8, 2026 19:28
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