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).Interface
No new interfaces are introduced.
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
Build succeeded. Let's run it to reproduce the issue.
Assistant
Reproduced. Now let's find what the empty statement node type is - likely the AST produces a node with empty type or empty Location for the trailing
;.Assistant
Need to put the tool inside module or a cmd dir. Let's create it under /pyscn/cmd/debugtool temporarily.
Assistant
Now update
isTriviato treat the bare;separator token as trivia too.Assistant
Now let's rebuild and test.
Assistant
dead_code_count: 0now. Let's verify with more detail that it doesn't break other legit trailing-semicolon-with-actual-dead-code cases (e.g., real unreachable code after semicolon-separated statements likereturn x; y = 1).Assistant
Real dead code (after
return x; y = 1) is still correctly detected (y = 1andreturn yare unreachable), while the pure semicolon-only case (i) yields no false findings. This confirms the fix is well-targeted.Now let's clean up the temporary debug tool and run the existing test suite.
Assistant
Let's run the full test suite to make sure nothing else broke.
Assistant
All tests pass. Let's check
git difffor the final changes and clean up temp files.Assistant
Clean, minimal diff confined to the parser's
isTriviahelper. Let's clean up temporary files used for testing.Assistant
Now let's go through the checklist explicitly.
Assistant
Checklist review:
-
If an error was reported in the issue description, I have successfully reproduced it. ✅ I built the
pyscnbinary from source, created the exactsemi_repro.pyfrom the issue, ranpyscn analyze --json --no-open, and confirmed the JSON report contained the two spuriousunreachable_branchwarning findings withcode: ";"andstart_column: 0, end_column: 0, matching the issue exactly. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. ✅ After tracing the root cause (tree-sitter represents a trailing/inline
;as an anonymous;token that is a direct sibling of statements inside ablock/modulenode; the AST builder'sbuildBlock/buildModulewere not filtering it out, so it became a synthetic statement node of type";"that the CFG builder placed in its own basic block right after the terminatingreturn/raise, which the reachability analyzer then flagged as an "unreachable branch"). I fixed this by extending the existingisTriviahelper (already used to filter comments/line-continuations when building statement lists) to also treat the anonymous;token as trivia. Re-running the same repro produceddead_code_count: 0— no findings at all for either function. -
I have thought about edge cases and made sure my fix handles them as well. ✅ I tested:
- A statement that has real dead code after a semicolon on the same line as a
return(return x; y = 1followed by anotherreturn y) — the fix still correctly reportsy = 1and the followingreturn yas unreachable, showing the fix doesn't suppress genuine dead-code detection, only the meaningless bare;. - A line with only semicolon-joined simple assignments and no dead code (
x = 1; y = 2; z = 3) — correctly produces zero findings. - Verified via a debug tool that printed the tree-sitter parse tree that
;only ever appears as an anonymous statement-separator token (never as a meaningful child inside expressions, slices, argument lists, etc.), so broadeningisTriviaglobally is safe and doesn't risk filtering out meaningful semicolons elsewhere (Python has no other syntactic use for a bare;). - The fix is general (not hardcoded to specific line/column numbers from the issue) — it addresses the root cause at the AST-building stage so it applies uniformly to any function, any nesting level, and both
return;/raise;-style trailing semicolons as well as module-level trailing semicolons.
- A statement that has real dead code after a semicolon on the same line as a
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. ✅ Ran
go build ./...(succeeds) andgo test ./...across the entire repository (all packages reportok, includinginternal/parser,internal/analyzer,service,app,domain,integration,mcp, etc.), confirming no regressions.
I also removed all temporary debug artifacts (
cmd/debugtool, generated.pyscnreport directories, and repro scripts) so the final diff is minimal and focused solely on the actual fix.-
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →