[DeadCode] Skip RemoveDeadIfBlockRector on empty if with elseif and trailing else - #8446
Merged
Merged
Conversation
…railing else
An empty if body followed by elseif and else was merged into
"if (!cond && elseifCond) {...} else {...}". When the original if
condition was true, the negated condition made the else branch run,
which the empty if body never did. Keep such code unchanged.
Fixes rectorphp/rector#9884
Claude-Session: https://claude.ai/code/session_01MszFhfN8nK7KR3mBjda8P2
TomasVotruba
force-pushed
the
fix-remove-dead-if-block-else
branch
from
September 3, 2026 19:48
4a5fa0d to
2417780
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes rectorphp/rector#9884
RemoveDeadIfBlockRectorchanged behavior on an emptyifbody followed byelseifand a trailingelse:was merged into:
When the original
ifcondition was true, the empty body ran nothing. After the merge the negated condition is false, so theelsebranch runs instead - a semantic change.The merge is only safe when there is no trailing
else. This bails out and keeps the code unchanged when anelseis present. The existingempty_if_with_elseif_and_else.php.incfixture (which encoded the wrong output) becomes askip_fixture.https://claude.ai/code/session_01MszFhfN8nK7KR3mBjda8P2