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/unreachable-branch implementation and relevant tests, then reproduce the reported output before making a narrowly scoped source change.
- Assistant
rgis unavailable, so I’ll usegrep/findto locate the analyzer and tests without installing unnecessary tooling. - Assistant
The initial search confirms a Go service around Python analysis. I’ll now inspect the Python bridge and dead-code service files, plus test names, to identify where CFG node types and source locations are transformed into findings.
- Assistant
I found the core implementation in
internal/analyzer/dead_code.go. I’ll read it alongside the CFG node definition and parser/builder logic to determine how a trailing semicolon is represented and where filtering is safest. - Assistant
The detector currently treats any block with at least one parser node as reportable. The issue likely arises because tree-sitter emits an unnamed
;node that the CFG builder adds as a statement. I’ll inspect parser node fields, statement traversal, and code/location extraction, then run the CLI repro to verify the exact internal behavior. - Assistant
I’ll inspect the AST type constants and CFG builder’s generic statement path. Then I’ll build the existing binary and run the supplied source through JSON output, preserving the report outside the repository if needed.
- Assistant
The CFG’s reachability API counts blocks solely by statement slice length, so an empty/synthetic node must be excluded either before insertion or when collecting unreachable blocks. To avoid changing CFG behavior globally, I’ll identify the exact semicolon node shape from parser output and reproduce via CLI.
- Assistant
The first reproduction build was blocked by an environment configuration (
GOMODCACHE/GOPATHunset), not by source. I’ll inspect the parser’s fallback mapping and available Go environment/cache, then rerun with an explicit temporary GOPATH if dependencies are already cached or downloadable. - Assistant
The parser fallback confirms
;becomes a generic node with type";"and zero-based tree-sitter point coordinates. I’ll rerun the supplied repro withGOPATH=/root/go, then inspect AST/body and CFG blocks using a temporary in-repository diagnostic Go test (removed afterward) if CLI output alone is insufficient. - Assistant
Go also requires a build cache because
HOMEis unset. I’ll provide explicit/tmpbuild-cache paths and rerun; this changes no repository files. - Assistant
The repro succeeded: the CLI reports exactly two warning dead-code issues (its nonzero exit is expected when findings exist) and writes JSON to its report path rather than stdout. I’ll extract those findings, then choose a source-level predicate for non-actionable empty statement nodes. Since adding tests is prohibited, I’ll validate with temporary diagnostics and existing suites only.
- Assistant
The existing code already defines the semicolon representation explicitly in raw metrics. I’ll inspect that helper and nearby conventions, plus dead-code tests, to decide whether to centralize the predicate in parser/analyzer code or add a detector-local filter with minimal API impact.
- Assistant
A detector-local filter is the safest scope: explicit
passremains a real source statement, while tree-sitter’s generic";"token is only a separator. I’ll make reportability statement-aware so that (1) semicolon-only unreachable blocks create no finding or dead-block count, and (2) mixed blocks such asreturn; x = 1still reportx = ...with its real location/code rather than including the separator. This avoids mutating the CFG or changing unrelated raw-metric behavior. - Assistant
The implementation now filters separator nodes consistently from block eligibility, location, and rendered code. I’ll rebuild and rerun the exact supplied repro; success means the dead-code count is zero and no
code: ";"finding exists. I’ll also run a temporary mixed same-line case to ensure genuine unreachable code after a semicolon remains detected. - Assistant
The exact repro is fixed: exit status is now 0, summary count is 0, and there are no dead-code files/findings. The mixed case correctly keeps the real unreachable assignment and omits
;from its code. Columns for real findings are independently zero in this architecture, but the reported impossible semicolon location is eliminated as requested.Next I’ll run the focused analyzer tests (including race-free standard package tests), then the broader Go test suite to catch service/summary assumptions about dead-block counts.
- Assistant
Focused tests all pass. One consistency edge remains:
DeadCodeDetector.HasDeadCode()currently bypassesDetect()and asks raw reachability whether any node exists, so it would still return true for a semicolon-only block even though no finding is emitted. I’ll inspect its usages/tests and, if safe, align it with filtered detector results before running the full suite. - Assistant
HasDeadCodehas no external in-repo callers and should reflect detector findings rather than lower-level CFG occupancy. I’ll align it by usingDetect().DeadBlocks, ensuring all public detector APIs agree that a trailing separator is not dead code. - Assistant
The API is now internally consistent, formatting and diff checks pass. I’ll run
go test ./...as the complete existing Go suite, then rerun the exact CLI reproduction once more against the final source and inspect repository status for accidental artifacts. - Assistant
The complete Go suite passes across all packages. For final verification I’ll rebuild from the final source, rerun the exact two-function repro, and check that explicit
passafterreturn;remains reportable (confirming the filter targets only synthetic separators, not user-authored statements). Then I’ll review the final diff/status. - Assistant
Final review is clean: only
internal/analyzer/dead_code.gochanged,git diff --checkpasses, the exact repro produces zero findings, mixed genuine dead code remains detected, and explicitpassbehavior is unchanged.Checklist:
- Successfully reproduced the reported error. Before the fix, the supplied
semi_repro.pyproduced twounreachable_branchwarnings withcode: ";", forfandg. - Confirmed the fix resolves the error. After the final rebuild, the exact repro exits successfully with
dead_code_count: 0and no dead-code files/findings. - Considered edge cases. A mixed
return; x = 1still reports the unreachable assignment while excluding the separator; a user-authoredreturn; passstill reportspass. Detector counts, rendered code, source lines, andHasDeadCode()all use the filtered semantics. - Ran affected existing tests. The focused analyzer/service/app/domain/integration/CLI/MCP tests passed, followed by the complete
go test ./... -count=1suite with all packages passing.
I’ll now submit the verified change.
- Successfully reproduced the reported error. Before the fix, the supplied
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 →