ISSUE DESCRIPTION [BUG][auto] deadcode-trailing-semicolon-empty-stmt: trailing-semicolon…
- User
ISSUE DESCRIPTION
[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
I'll start by exploring the repository structure and locating the dead-code analyzer so I can reproduce the trailing-semicolon false positive.
- Assistant
Let me look for dead code related files.
- Assistant
I'll inspect the dead-code analyzer implementation next.
- Assistant
Let me continue reading the file, especially the parts that collect unreachable findings.
- Assistant
Let me look at the analyzeDeadBlock function and getNodeDescription, plus GetUnreachableBlocksWithStatements.
- Assistant
Let me read analyzeDeadBlock and getNodeDescription etc.
- Assistant
I'll check how statements and empty nodes are represented in the CFG and code extraction paths.
- Assistant
The
;node type suggests empty statements — I'll look for where those are created in the CFG/parser. - Assistant
Let me look at how expression statements and empty/semicolon statements are handled in the AST builder and CFG builder.
- Assistant
Maybe trailing semicolon creates a separate node. Let me look at the tree-sitter structure for return_statement with semicolon, and how statements are collected into blocks.
- Assistant
Let me try to build the project and reproduce the issue.
- Assistant
Building pyscn and reproducing the reported false positive next.
- Assistant
Need to set GOPATH
- Assistant
Build seemed to complete. Let me check if the binary exists and run the repro.
- Assistant
There are two dead-code issues — I'll inspect the JSON report to confirm they match the bug.
- Assistant
Reproduced successfully. Next I'll inspect how the AST/CFG represents trailing-semicolon empty statements.
- Assistant
I'll inspect how unreachable statement-bearing blocks are collected and how the CFG treats empty /
;nodes. - Assistant
Let me read GetUnreachableBlocksWithStatements and the CFG builder statement handling related to return.
- Assistant
Let me look at the default case in processStatement and how return/raise creates unreachable blocks.
- Assistant
I'll check existing dead-code tests and how column info is produced for findings.
- Assistant
Let me look at how domain findings are converted from analyzer findings - maybe columns come from somewhere.
- Assistant
So the ";" tree-sitter node is coming through as a generic Node with Type ";". Looking at columns 0-0 - getLocation might be returning 0 for some reason, or conversion doesn't set columns.
- Assistant
I'll check
IsEmptyand write a small dump of the CFG for the repro case. - Assistant
Let me look at how tests construct things.
- Assistant
Let me look at the test helper and how they get the ast... result.AST.
- Assistant
I'll create a quick test script to dump the CFG.
- Assistant
I have a clear picture: trailing
;becomes an empty statement node and gets flagged. I'll filter those out in the dead-code analyzer. - Assistant
I'll check how the module/block body includes
;nodes, and whether skipping them at build time is cleaner. - Assistant
Looking at isTrivia:
- Assistant
Implementing the filter in the dead-code analyzer and cleaning up the temporary probe.
- Assistant
Now I'll update
dead_code.goto skip blocks whose statements are only empty;nodes. - Assistant
I'll jump to the right place in the file and apply the edit there.
- Assistant
Now I can replace.
- Assistant
Adding helper functions and teaching
getBlockCode/analyzeDeadBlockto ignore empty statements. - Assistant
I'll also make start/end line and code extraction prefer non-empty statements when a block mixes both.
- Assistant
Updating
getBlockCodeandgetNodeDescriptionto handle empty statements. - Assistant
I'll update getBlockCode to skip empty and start/end line to skip empties for finding locations - but carefully because terminator detection uses the samefunctions.
- Assistant
Verifying the fix with a rebuild and a few edge-case scenarios.
- Assistant
Original case is fixed. Checking edge cases next.
- Assistant
The edge-case file had a syntax error — fixing it and re-running.
- Assistant
return y;;is invalid - Python doesn't allow empty statement after semicolon in that way... actually wait,return y;is valid (the semicolon ends the simple statement list).return y;;has an em... - Assistant
Typo in script. Fix dump.
- Assistant
Edge cases look good. Running the existing dead-code unit tests.
- Assistant
All relevant tests passed. Cleaning up temp files and checking the final diff.
- Assistant
I'll update the dead-code docs to note that empty-statement blocks are filtered out.
- Assistant
I'll add a note about trailing semicolon empty statements.
- Assistant
The current file was switched to docs. Need to goto.
- Assistant
Now replace.
- Assistant
I accidentally corrupted a heading — fixing that now.
- Assistant
Running a final verification rebuild, then submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.