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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me explore the parser to understand node types and how empty statements are represented.
Assistant
Now let me understand how an empty statement would be parsed. Let me search for "empty_statement" in the parser.
Assistant
Now let me build the project and run the analyze command to see the actual behavior:
Assistant
Now let me reproduce the issue:
Assistant
Issue reproduced. Let me see the complete JSON report:
Assistant
Let me understand how the CFG builder handles empty statements:
Assistant
Let me create a small test to print the AST for the empty statement:
Assistant
Now I have enough info. Let me write the test programproperly:
Assistant
The trailing
;shows up as a node of type;(notNodeExpr). Let me trace through to see what's happening:Assistant
Now I see. Tree-sitter encounters the
;as an unknown node type, so the parser creates aNodeType(";")literal. Now let me look at the cfg_builder:Assistant
Now I understand the flow. Let me look at the dead code analyzer more carefully and look at the relevant places to make the fix:
Assistant
Let me examine how
passis represented in the AST:Assistant
Interesting!
pass;produces both a Pass node AND a;node. Let me check what the analysisdoes with this:Assistant
Now let me look at how the reachability analyzer finds unreachable blocks:
Assistant
Now let me check what
IsEmpty()does:Assistant
Let me trace what CFG gets built for the bug example:
Assistant
Let me check how the JSON serialization handles the location:
Assistant
Let me find where the analyzer's
DeadCodeFindinggets converted to the domain'sDeadCodeFinding:Assistant
Now I understand the full picture. Let me look at the existing
analyzeDeadBlockand design the fix:Assistant
Now let me look at the existing test file for dead_code to understand testing conventions:
Assistant
Let me check what happens with
pass;:Assistant
Now I have a clear understanding. Let me implement the fix. First let me clean up the test file:
Assistant
Now let me look at the analyzeDeadBlock function once more and design the fix:
Assistant
Now let me implement the fix. I'll add a helper function to check if a block only contains empty/no-op statements and modify
analyzeDeadBlockto skip such blocks:Assistant
Now let me look at how getNodeDescription handles the
;case to verify my understanding:Assistant
Now let me implement the fix. I'll add helper functions and modify the detect logic:
Assistant
Now I'll implement the fix:
Assistant
Let me use a different approach with sed and patch:
Assistant
Now let me verify the patches were applied correctly:
Assistant
Let me verify the file builds:
Assistant
Now let me rebuild the binary and verify the fix:
Assistant
Excellent! The bug is fixed. Now let me run the existing tests to ensure I haven't broken anything:
Assistant
All existing tests pass. Now let me also test with a real file from the issue:
Assistant
Let me test various edge cases:
Assistant
Wait, this is strange. The output shows no files in dead_code. Let me check if maybe the test_paths arenot being detected or there's something wrong with my test file. Let me look:
Assistant
Let me check what's happening - my test file has a syntax error. Let me simplify and try again:
Assistant
Let me look at the test cases more carefully. The f3 case shows
code: ";\nassignment"which is still showing the;. Let me trace what happens:Assistant
Let me also filter empty statements from the code representation, so when a block has both
;and real dead code, the;is not included:Assistant
Let me update getBlockCode to skip empty statements:
Assistant
Now the code field for f3 is just "assignment". Let me verify the original test case:
Assistant
The bug is fixed. Let me test the real bioconvert examples mentioned in the issue:
Assistant
All trailing semicolons are filtered. Now let me also test that real dead code is still detected:
Assistant
Let me run all the analyzer tests to make sure nothing is broken:
Assistant
All dead code tests pass. Let me also run the broader analyzer tests:
Assistant
All tests in the analyzer package pass. Let me also run the service package tests:
Assistant
All service tests pass. Let me also test some edge cases like the issue mentioned bioconvert:
Assistant
Let me test additional edge cases - break/continue with semicolons:
Assistant
Excellent! All edge cases are handled. Let me view the complete diff to review the changes:
Assistant
Let me clean up temp files and view the final state of the key parts:
Assistant
Let me do a final comprehensive test to ensure everything works:
Assistant
Excellent! The fix is working correctly. Let me clean up and run more tests:
Assistant
Good. Let me also test the issue's exact reproduction case one more time to verify:
Assistant
The fix is complete. Let me clean up and run all the analyzer tests once more:
Assistant
All analyzer tests pass. Let me also verify the service tests:
Assistant
All tests pass. Let me also do a final summary of what was changed:
Assistant
Let me do one final sanity check to verify the fix works:
Assistant
The fix works correctly. Let me also run the parser tests just to ensure no regressions:
Assistant
All tests pass across all packages. Let me now also verify the final state of the change:
Assistant
Only one file is modified, and the change is minimal and targeted. Let me go through the checklist:
Checklist Review
-
[x] If an error was reported in the issue description, I have successfully reproduced it.
- I created
/tmp/test_semi.pywith the exact code from the issue and ranpyscn analyze --json --no-open. The output showed the false-positive findings withcode: ";",reason: "unreachable_branch", and0-0column range.
- I created
-
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- After the fix, the same
/tmp/test_semi.pyproduces no findings (total_findings: 0). - The bioconvert-style examples mentioned in the issue (gff.py:618, tbl.py:114, things.py:753 and :780) all produce no findings as expected.
- Real dead code is still detected correctly (verified with
/tmp/test_real_dead.py).
- After the fix, the same
-
[x] I have thought about edge cases and made sure my fix handles them as well.
- Edge cases tested:
- Trailing semicolons only (filtered, no finding)
- Trailing semicolons + real dead code (real dead code still detected,
;filtered from code field) break;(filtered)continue;(filtered)raise ValueError();(filtered)pass;(no issue sincepassisn't a terminator)- Bare
pass(no issue sincepassisn't a terminator) - Mixed semicolon patterns from bioconvert files (all filtered)
- Edge cases tested:
-
[x] I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
- All
TestDeadCode*tests pass. - All
internal/analyzer/tests pass. - All
service/tests pass. - All
internal/parser/tests pass. - All other packages (
app/,cmd/pyscn/,domain/,integration/,internal/config/,internal/mockdetector/,internal/reporter/,internal/version/,mcp/) pass.
- All
Summary of changes
The fix in
internal/analyzer/dead_code.go:- Added
isEmptyStatement(node *parser.Node) boolhelper that detects no-op statements: trailing;(tree-sitter parses asNodeType(";")), barepass, and empty expression statements. - Added
hasOnlyEmptyStatements(block *BasicBlock) boolhelper that checks if all statements in a block are no-ops. - In
Detect(): filter unreachable blocks containing only empty statements before reporting them as dead code findings, sodead_blockscount andfindingsstay consistent. - In
analyzeDeadBlock(): defensive guard that also filters blocks containing only empty statements (in caseanalyzeDeadBlockis called directly). - In
getBlockCode(): skip empty statements when building the synthesized code snippet, so a block containing both;and real dead code reports only the real dead code (e.g.,"assignment"instead of";\nassignment").
-
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 →
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 →