Description
When a condition is duplicated in an else if chain, the later branch is unreachable because the else path already implies the previous condition is false. The analyzer should flag these cases to surface dead code and logic errors.
Add a dedicated analysis pass that:
- Finds conditional branches whose condition duplicates a dominating
if condition along the false successor path.
- Canonicalizes operands (including commutative comparisons) to avoid missing equivalent conditions.
- Skips cases where intervening writes can change the compared values.
- Uses debug info plus a light source check to confirm the control-flow is truly an
else if chain.
Emit a DuplicateIfCondition warning with precise source location and a short explanation.
Acceptance Criteria
- A new warning
DuplicateIfCondition is emitted for duplicate conditions in else if chains.
- Equivalent conditions with commuted operands are detected.
- Distinct conditions and separate
if statements are not flagged.
- Tests cover positive and negative cases.
Description
When a condition is duplicated in an
else ifchain, the later branch is unreachable because theelsepath already implies the previous condition is false. The analyzer should flag these cases to surface dead code and logic errors.Add a dedicated analysis pass that:
ifcondition along the false successor path.else ifchain.Emit a
DuplicateIfConditionwarning with precise source location and a short explanation.Acceptance Criteria
DuplicateIfConditionis emitted for duplicate conditions inelse ifchains.ifstatements are not flagged.