unreachable-after-break¶
Category: Unreachable Code
Severity: Critical
Triggered by: pyscn analyze, pyscn check
What it does¶
Flags statements that appear after a break statement inside a loop.
Why is this a problem?¶
break exits the enclosing loop immediately. Anything after it in the same block runs zero times.
Common causes:
- A misplaced increment or accumulator update — the author intended it to run on the final iteration.
- Leftover logging or cleanup — moved below the
breakduring a refactor. - Confused control flow — the author expected
breakto skip only part of the iteration.
The code is unreachable, so tests cannot cover it and bugs inside it will never surface.
Example¶
Use instead¶
Perform the work before the break, or remove the dead statement.
Options¶
| Option | Default | Description |
|---|---|---|
dead_code.detect_after_break |
true |
Set to false to disable this rule. |
dead_code.min_severity |
"warning" |
"critical" keeps only this kind of finding; "info" surfaces more. |
dead_code.ignore_patterns |
[] |
Regex patterns matched against the source line; matches are suppressed. |
References¶
- Control-flow graph reachability analysis (
internal/analyzer/dead_code.go). - Rule catalog · Unreachable after continue · Unreachable after return