Skip to content

[BUG] dead-code scanner false positive — reports reachable code after early return as unreachable #105

Description

@Wolfvin

Bug

codelens dead-code reports false positives on this common Python pattern:

if condition:
    return None
return {"key": "value"}  # ← flagged as unreachable — but it IS reachable when condition is False

Evidence

PR #96 (fix for issue #93) found 7 of 18 reported 'unreachable' blocks in scripts/commands/analyze.py were this pattern. The worker 'fixed' them by adding else: after the early return — which Python style guides discourage — purely to satisfy the scanner, not because the code was actually unreachable.

Root Cause

Dead-code scanner in scripts/deadcode_engine.py (or equivalent) classifies any code following a return inside an if block as unreachable, without checking that the code is in the else branch (i.e., only reachable when the if condition is False).

Expected Behaviour

if x: return early_value\nreturn normal_value should NOT be flagged as unreachable. Only code after an unconditional return (not guarded by if) should be reported.

Impact

  • False positives create noise and cause workers to make unnecessary 'style' refactors
  • Adds else: after early returns — an antipattern per PEP 8

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions