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 to understand the codebase and find the relevant dead-code analyzer.
Assistant
This is a Go repository (go.mod present) but has Python code too. Let me look for the dead-code analyzer. The issue mentions "dead-code detector" and "CFG nodes". Let me search for "unreachable_branch" and related terms.
Assistant
The main file is
/pyscn/internal/analyzer/dead_code.go. Let me explore it.Assistant
I need to make only one tool call at a time. Let me combine them.
Assistant
Let me open the dead_code.go file to see the relevant logic.
Assistant
Let me look at the parser to understand what node type an empty statement (trailing semicolon) produces.
Assistant
Let me look at the parser to understand how empty statements from trailing semicolons are represented.
Assistant
Let me reproduce the issue. First let me build the tool.
Assistant
Build succeeded. Now let me create the repro file and run it.
Assistant
Reproduced. Let me see the full findings structure in the JSON.
Assistant
Confirmed. The
codeis;which is the empty statement's text. Now let me understand the node. The empty statement is aNodeExprwith no children, and its text is;.Let me look at how the block statements are built from the CFG and what the node looks like. Let me check how
getBlockCodegets;. ActuallygetNodeDescriptionreturns "expression" for NodeExpr. But the actual code is;. So thecodefield comes from somewhere else. Let me check how the finding'sCodefield gets the;value.Wait, the JSON shows
"code": ";"butgetBlockCodereturns node descriptions like "expression". Let me look more carefully. Maybe the code field is set differently. Let me look at how DeadCodeFinding.Code is populated and serialized.Actually in
analyzeDeadBlock,Code: dcd.getBlockCode(block). And getBlockCode uses getNodeDescription which returns "expression" for NodeExpr. But the JSON shows ";". So maybe the finding Code is overridden somewhere, or the report serialization uses something else.Let me search for where code is set to the raw text.
Assistant
The JSON shows
"code": ";"butgetBlockCodereturns "expression" for NodeExpr. The report must override this somewhere. Let me check the service layer that builds the JSON.Assistant
Let me check the report generation which may re-extract the code from source.
Assistant
Let me look at the report builder for dead code findings to see where
codegets set to;.Assistant
Let me check where the code field might be enriched from source. The JSON shows
;while getBlockCode returns "expression". Let me look at the report generation in cmd/pyscn. Maybe there's a report assembler that reads the source line and extracts.Assistant
Let me look at how the JSON report is generated and where the code
;comes from. Let me search for "report" in the analyze command and where DeadCode is written to JSON.Assistant
Let me search the whole repo for where code might be set from source text (reading source line).
Assistant
Let me check
analyze_formatter.goaround line 156, which uses lines.Assistant
Let me look at the full flow of the dead code result through the app usecase to find where code is enriched.
Assistant
Let me check the parser Node struct and whether nodes carry their source text.
Assistant
Let me write a debug program to dump the AST of the repro file and understand what node type the empty statement produces.
Assistant
Now let me write a debug program to dump the AST of the repro functions.
Assistant
Running a separate module is complex. Let me instead add a temporary debug print in
dead_code.goanalyzeDeadBlockto print the node types and code, then rebuild and run.Assistant
Let me add a temporary debug print in
analyzeDeadBlockto see the node type and code.Assistant
Let me check the DeadCodeFinding struct and its JSON tags precisely.
Assistant
Let me add a temporary debug print directly in
analyzeDeadBlockand rebuild.Assistant
I need to add the "fmt" import. Let me do that.
Assistant
Now I understand - the empty statement node has type
;(a literal NodeType), not NodeExpr. Let me see how this node gets created in the AST builder.Assistant
The
;node comes from tree-sitter's default case creating a generic node with type";". Let me check the reachability analyzer'sGetUnreachableBlocksWithStatements.Assistant
Let me look at the CFG builder's generic statement handling.
Assistant
Let me check how the DeadCode score is computed to understand the impact of dead_blocks count.
Assistant
The score is based on
OverallDeadRatio = DeadBlocks/TotalBlocks. So to fully fix (score should be 100, 0 dead blocks), I should filter empty statements where dead blocks are counted. Let me checkIsEmpty()usages to decide where to filter safely.Assistant
Now I have a clear understanding. Let me revert my debug changes to dead_code.go first.
Assistant
Let me check
generateDescriptionandgetBlockContextsignatures/usage.Assistant
Now let me implement the fix. First, let me add helper functions and modify
analyzeDeadBlockin dead_code.go.Assistant
Now let me modify reachability.go to also exclude blocks with only empty statements from the dead-block count.
Assistant
Now let me add the
HasSignificantStatementsmethod to BasicBlock in cfg.go.Assistant
Now let me build and test.
Assistant
Dead Code is now 100/100 (0 issues). Let me inspect the JSON structure to confirm findings are gone.
Assistant
The fix works — 0 findings, 0 dead blocks. Now let me verify legitimate dead code (after return, without trailing semicolon) is still detected, and that mixed blocks (real statement + trailing
;) report the real statement but not the;.Assistant
The fix works correctly:
;no-ops are filtered, real unreachable statements are still reported. Let me run the existing dead-code and analyzer tests to ensure no regressions.Assistant
All tests pass. Let me also run the domain and app tests to be thorough.
Assistant
All tests pass. Let me test additional edge cases: multiple trailing semicolons and
;used as a separator between real statements.Assistant
Interesting —
pass_after_return(return followed bypass) shows 0 findings. Let me test it in isolation to understand whether this is pre-existing behavior or a regression.Assistant
In isolation
pass_after_returnis detected. Let me re-run the combined edge file to investigate the discrepancy.Assistant
The combined file shows
total_files=0— likelyreturn x;;is a syntax error causing the whole file to be skipped. Let me verify.Assistant
return x;;is a Python syntax error (the file gets skipped by the parser — pre-existing behavior). Let me re-test edge cases with valid Python.Assistant
semi_then_real(return y; z=2) should reportz = 2as unreachable but shows 0 findings. Let me check if the file has a syntax error again.Assistant
;;(double semicolon) is also invalid Python — only a single trailing;is valid. Let me re-test with only valid syntax.Assistant
All valid edge cases work correctly:
separator(a = 1; b = 2): no false positive ✓trailing_in_branch(return 1;):;filtered, no finding ✓pass_after_return(return x/pass): realpassstill detected as critical ✓semi_then_real(return y;/z = 2):;filtered, realz = 2still reported ✓
Let me check all callers of the modified reachability functions to ensure no unexpected impact.
Assistant
All callers are within the dead-code analysis path. Let me check whether any existing testdata/tests use trailing semicolons that could be affected.
Assistant
Those are JS code in a string and a comment, not Python trailing semicolons. Let me verify the existing dead-code testdata still produces expected results by running the specific dead-code tests once more and checking the testdata file.
Assistant
All tests pass. Let me review the final diff to ensure it's clean.
Assistant
The diff is clean. Let me do a final confirmation run on the original repro from the issue.
Assistant
The original repro now produces 0 findings and 0 dead blocks. Let me verify git status to ensure no stray files were left behind.
Assistant
I left a stray
.bakfile. Let me remove it.Assistant
Clean — only the three intended files are modified. Let me run a final build + vet and the full analyzer/service test suite to confirm everything is green.
Assistant
Everything builds and passes. Let me clean up the temp repro files (not in the repo, so they won't be submitted, but good hygiene) and do a final review.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.