Skip to content

feat : detect duplicate else-if conditions as unreachable branches #33

@SizzleUnrlsd

Description

@SizzleUnrlsd

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions