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
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me explore further to understand the structure of the project,particularly looking for the dead-code analyzer.
Assistant
Let me explore the parser code to understand node types:
Assistant
Let me look at how the parser handles empty statements:
Assistant
Let me check the dead_code_test.go to understand the tests:
Assistant
Let me first reproduce the issue:
Assistant
I've reproduced the bug. Let me understand how the parser represents empty statements from
;:Assistant
Let me put the debug code inside the actual project structure:
Assistant
Now I see - the parser creates
;nodes for empty statements. Let me modify the debug program to print more info:Assistant
Now I see - the parser creates nodes with type
;for empty statements from trailing semicolons. The locations are L3:32-L3:33 and L8:12-L8:13. Note that they have valid locations, not 0-0.The issue is that when these empty
;nodes are filtered down through the CFG, they're treated as a new block which becomes unreachable. Let me look at the CFG builder to understand:Assistant
Let me see the cfg.go to understand BasicBlock:
Assistant
Now let me look at the reachability analyzer:
Assistant
Let me look at where the
;node type comes from in the parser:Assistant
Let me understand the tree-sitter type for
;:Assistant
Let me look at the cfg_builder to find where the unreachable block gets created and the
;statement ends up:Assistant
Let me understand
passparsing too:Assistant
Let me check the existing constants:
Assistant
Let me also look at the dead_code JSON output structure:
Assistant
I see that
StartColumnandEndColumnare not being passed through. Let me check what the actual JSON shows again - the output has"start_column": 0, "end_column": 0. So where do these come from?Looking at the JSON output earlier:
"location": { "file_path": "/tmp/semi_repro.py", "start_line": 3, "end_line": 3, "start_column": 0, "end_column": 0 },The
start_columnandend_columnare 0 in the JSON. This mustcome from the domainDeadCodeLocationstruct. Let me look at it:Assistant
Now let me check how the report handles
start_column:Assistant
Now I have enough understanding. Let me design and implement the fix. Let me first check the tests to see what exists:
Assistant
Let me check if there's any constant for the
;type already:Assistant
Let me look at the parser ast.go to add a proper constant:
Assistant
Now let me implement the fix. First, let me look at the dead_code.go once more to plan the exact edits:
Assistant
Now I'll implement the fix:
Assistant
Now let me make the fix. I'll modify the
Detect()function and add helper functions:Assistant
Let me make the edit to the
Detect()function andadd helper functions to filter out empty statements.Assistant
Now let me edit the
Detect()function to filter out empty-only blocks:Assistant
Now let me add the helper functions. Let me look at where to add them:
Assistant
Now let me build and verify:
Assistant
The fix works. Let me verify the JSON output:
Assistant
The fix works for the original repro case. Now let me test that it still detects real dead code:
Assistant
We now detect 1 issue (only 1 critical, which is the dead code after raise). The other dead code (after return) isn't being detected. Let me check if this is the existing behavior:
Assistant
Let me also test with mixed cases (real dead code + trailing semicolon):
Assistant
The current fix handles the main issue from the report. However, for a mixed case (with both
;and real dead code), the empty statement still appears in the report. Let me improve the fix to also filter empty statements from the code shown in mixed blocks:Assistant
Let me look at the
analyzeDeadBlockfunction to see if I should also filter at that level:Assistant
Let me run the existing tests to make sure I haven't broken anything:
Assistant
All tests pass. Let me also run the broader analyzer tests:
Assistant
Let me also run more tests for edge cases:
Assistant
The main fix works, but I should also improve the
getBlockCodefunction to filter out empty statements from the code shown in mixed-case blocks. Let me also improve thegetBlockStartLineandgetBlockEndLinesimilarly:Assistant
Let me focus on the minimum viable fix that addresses the specific issue. Let me verify the original repro case one more time:
Assistant
Let me also run the broader test suite to make sure nothing else broke:
Assistant
Let me test more edge cases including
passonly in dead code:Assistant
Wait, let me check the JSON output to see what's detected:
Assistant
There's a parse error! Let me check what's wrong with mytest file:
[/tmp/edge_pass.py] Parse error: syntax errors found in source codeLet me check the file:
Assistant
Python doesn't allow a bare
;on its own line as a statement (only asa separator between statements). Let me fix the test:Assistant
The fix works correctly:
f1(dead block with onlypass): Not reported. ✓f2(dead block withpass+ real dead code): Reported asunreachable_after_return. ✓f3(normal function with onlypass): Not reported. ✓f4(dead block with onlypass;): Not reported. ✓
Now let me also look at the original test cases to ensure they still pass:
Assistant
Let me also write a temporary script to confirm the fix works:
Assistant
The fix works correctly. Both
fandghave empty findings arrays. Let me also verify the fix doesn't break the broader test suite:Assistant
All tests pass. Let me clean up the temporary debug code:
Assistant
Let me look at the final diff to make sure everything is correct:
Assistant
The diff looks clean. Let me also check
git status:Assistant
Let me do one final sanity check with the original repro:
Assistant
The fix works correctly:
- Before: 2 issues (the empty
;statements being reported as dead code) - After: 0 issues
Let me clean up temp files:
- Before: 2 issues (the empty
Assistant
Let me do a final review of my fix:
Assistant
Let me do a final verification by reviewing the changes one more time and answering the checklist:
Assistant
Let me also do one more test to confirm the original repro:
Assistant
The fix works perfectly. Let me clean up temp files:
Assistant
Now let me go through the checklist and provide my final reasoning:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.