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.
pyscn version:
v1.22.5(commitbac7f16)Found via the FP-audit skill in repo
bioconvert/bioconvert@92f4655(4 real occurrences:bioconvert/utils/biocode/gff.py:618,tbl.py:114,things.py:753and:780).ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /pyscn, current file: none) bash-$
- Assistant
I’ll first inspect the repository structure and search for the dead-code analyzer and
unreachable_branchemission paths, then reproduce the reported output before making a focused source change. - Assistant
The detector is implemented in Go. I’ll inspect its collection logic, CFG node model, and relevant tests to understand how the Python parser represents the synthetic empty statement and choose the narrowest reliable filtering point.
- Assistant
The reporting method currently treats any nonempty
Statementsslice as actionable, regardless of whether those nodes contain source code. I’ll now inspect exact node fields, CFG construction, reachability filtering, and the command/build workflow, then run the CLI against the supplied repro to observe the actual node representation indirectly or through a small diagnostic if needed. - Assistant
I’ll create the repro outside the repository (so no test files are added), build the current CLI, and inspect its JSON output. I’ll also locate parser conversion code for anonymous punctuation nodes because the expected
code: ";"suggests the node type itself may be";"with zero coordinates. - Assistant
The initial build was blocked only because this sandbox has no
GOPATH/module-cache environment configured. I’ll set temporary Go cache paths and rerun. In parallel, the AST builder’s fallback at line 193 is likely where punctuation becomes a generic node, so I’ll inspect that code and the tree-sitter child traversal semantics. - Assistant
The CLI writes reports to its working directory rather than accepting
--output. I’ll run it from an isolated temporary directory with only the repro file, capture the report, then inspect CFG builder statement dispatch to see why semicolon nodes become separate blocks after terminators. - Assistant
The bug reproduces exactly with two
code: ";"findings. The semicolon is an anonymous tree-sitter token converted by the parser fallback into a genericNodeType(";"), and CFG construction processes it as a statement after the terminating node.I’ll inspect dead-code tests and statement handling in detail. The fix should filter blocks whose statements are only empty separator tokens before both counting and emitting dead code, while preserving real
passstatements and mixed blocks. That avoids a “findings: 0 but dead_blocks: 1” ghost result and is narrower than suppressing all zero-width or unknown nodes. - Assistant
A block-level-only check is insufficient for
return x;\nfoo(): both the synthetic separator and real unreachable code share the same block, so the report would still include;and could use its line as the finding start. I’ll inspect all methods that iterate block statements, then introduce a singleisEmptyStatementpredicate and consistently exclude separators from dead-code counting, locations, and code rendering without changing CFG semantics or suppressing explicitpass. - Assistant
I’ll implement the detector-side filter now. The predicate will recognize only the parser’s anonymous
";"token (plus nil defensively), notNodePass. Detection will count/report only blocks with at least one actionable statement; code and line extraction will skip separators in mixed blocks; andHasDeadCodewill use the same semantics so this repro is not considered dead code through that API either. - Assistant
The focused change is in place. I’ll rebuild and rerun the exact repro, checking not only that bare-semicolon findings disappear but that the dead-code section no longer retains ghost results. I’ll also test a mixed block (
return;followed by real code) to confirm the real unreachable statement remains reported with the correct line and without;in its code field. - Assistant
The exact repro now yields zero dead-code findings and zero dead blocks. The mixed case still reports the real
printon line 3 asunreachable_after_return, and no semicolon appears in its code.Next I’ll run the full analyzer package tests (which cover CFG/reachability/dead-code interactions), then the repository-wide Go tests. I’ll use the temporary cache environment needed by this sandbox.
- Assistant
All analyzer tests and the complete Go test suite pass. I’ll perform a final diff/status review to ensure only the intended source file changed, check formatting, and verify there are no repository artifacts from builds or repros before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →