Untitled conversation
- User
[BUG][auto] deadcode-trailing-semicolon-empty-stmt: trailing-semicolon empty statement reported as unreachable warning (code=";", col 0-0)
Description
The dead-code detector emits a
warning-severityunreachable_branchfinding whosecodefield is a bare;(an empty statement) whenever areturn/raisestatement is written with a trailing semicolon. In Python a trailing;is a valid (if unusual) statement separator, soraise X;parses asraise Xfollowed by an empty statement. That empty statement is technically unreachable, but reporting a no-op as actionable dead code is pure noise — there is nothing for the user to "remove" beyond a stylistic semicolon, and the finding points at literal;with an impossible0-0column range.Repro
Minimal synthetic Python (
semi_repro.py):def f(x): if x is None: raise ValueError("nope"); return x def g(y): return y;Run:
pyscn analyze --json --no-open semi_repro.pyActual output
Two dead-code findings (from the generated JSON report):
{"function_name": "f", "location": {"start_line": 3, "start_column": 0, "end_column": 0}, "code": ";", "reason": "unreachable_branch", "severity": "warning"} {"function_name": "g", "location": {"start_line": 8, "start_column": 0, "end_column": 0}, "code": ";", "reason": "unreachable_branch", "severity": "warning"}Expected behavior
Empty statements (the no-op produced by a trailing
;) should be filtered out before emitting dead-code findings — they carry no actionable signal. At most this is a low-severity style hint ("redundant trailing semicolon"), not awarning-severity unreachable-code finding. The0-0column range is also a symptom of the synthetic/empty node being reported.Priority rationale
P2 (visible but bounded inaccuracy, per the FP-audit rubric): the gist isn't wrong (the
;truly follows a terminating statement), but the output is misleading — awarningthat points at literal;with a0-0column range reads as a real defect when there is none. Bounded impact: only fires on the rare trailing-semicolon style.Suggested fix (good first issue)
Skip CFG nodes that correspond to empty statements (Python
pass-equivalent / bare;separators) when collecting unreachable-branch findings in the dead-code analyzer. - Assistant
Now let me find how the parser handles empty statements (the
;node type): - Assistant
Let me reproduce the issue first:
- Assistant
Reproduced. Now let's find where the
;node enters the AST/CFG: - Assistant
The
;separator token falls through to the default case inbuildNodeand becomes a generic statement node. Let me check whether anything relies on;nodes, and check the empty-statement semantics: - Assistant
Dead code issues went from 2 to 0. Now verify real dead code after a trailing semicolon is still detected:
- Assistant
Now I'll add regression tests. First to
TestDeadCodeDetection: - Assistant
Now a parser-level test. Let me check the existing test style:
- Assistant
Both suites pass. Run the broader test suite to check nothing else depended on
;nodes: - Assistant
All tests pass across the repo. Final checks:
- Assistant
Fixed. Summary of the change:
Root cause
tree-sitter-python emits the trailing
;inraise X;/return y;as an anonymous separator token that is a sibling of the statement in the block.buildNodeininternal/parser/ast_builder.gohad no case for it, so the default branch fabricated a generic AST node of type;. The CFG builder then placed that no-op node into the block following the terminator — an unreachable block — and the dead-code detector reported it as awarning-severityunreachable_branchwithcode: ";"and a column range (the synthetic node carries no meaningful span). Notably, already had a local workaround for these nodes (), confirming they were leaking into analyzers.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.