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
Reproduced. Let's inspect the JSON report.
Assistant
Good, reproduced exactly. Now let's find where CFG builder creates blocks for statements to understand where an "empty" block with code ";" comes from.
Assistant
Now let's check the default case in
buildNodetoo, since it's a generic fallback used for arbitrary constructs (in case unnamed nodes sneak into other statement lists likeif/for/trysuites built differently, or decorated statements, etc.)Assistant
Good, this confirms
extractBlockBodyusesbuildBlock's output, so fixingbuildBlockcovers function/if/for/while/try bodies. Now let's rebuild and test.Assistant
The finding is now gone (Dead Code 100/100, 0 issues). Let's verify the JSON directly to be thorough, and also test edge cases (semicolon-separated multiple statements, semicolons not at end, nested blocks).
Assistant
Now let's test edge cases: multiple statements separated by semicolons on one line, semicolon after normal (non-terminating) statement, semicolons in nested blocks, and actual real unreachable code after a trailing-semicolon return.
Assistant
Genuine unreachable code after both trailing-semicolon and normal
returnstatements is still correctly detected (no false positive for the semicolons themselves, and no false negative for the real dead code). Now let's run the existing test suite to check for regressions.Assistant
All tests pass. Let's run the full test suite to be safe.
Assistant
All tests pass. Let's clean up temp files and view the diff.
Assistant
Clean. Now let me go through the checklist:
- Reproduced the reported error: Yes — using the exact
semi_repro.pyfrom the issue, I confirmed the JSON report contained twounreachable_branchwarnings withcode: ";"and0-0column ranges before the fix. - Confirmed the fix resolves it: Yes — after the fix, the same file produces
Dead Code: 100/100 (0 issues)and thedead_code.filesarray isnull/empty; no more;-coded findings. - Edge cases considered: Tested (a) multiple semicolon-separated statements on one line (
x = a; y = b; return x + y), (b) double;;, (c)pass;inside anif, (d) genuine unreachable code following both a normalreturnand a semicolon-terminatedreturn/raiseto make sure real dead-code detection still fires correctly (it does, unaffected). The root-cause fix (filtering unnamed/anonymous tree-sitter tokens like the;separator when buildingblock/modulestatement bodies) is general — it doesn't special-case the dead-code analyzer, so it also prevents any other analysis stage (CFG, complexity, clones, etc.) from ever seeing bogus empty-statement AST nodes, and it does not hardcode based on literal;text but on the tree-sitter "named vs unnamed" node distinction, which is a general concept covering any similar stray punctuation. - Existing tests pass: Ran
go build ./...andgo test ./...for the whole repository — all packages pass (internal/parser,internal/analyzer,service,app,domain,integration,mcp, etc.), confirming no regressions.
- Reproduced the reported error: Yes — using the exact
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 →