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 start by exploring the repository structure to understand the codebase and locate the dead-code analyzer. Let's first get an overview.
- Assistant
Let me explore the directory structure more to understand the project.
- Assistant
This is a Go project (go.mod) with Python bindings. Let me explore the Go source code structure. The dead-code analyzer is likely in the
internaldirectory. - Assistant
Let me explore the analyzer and parser directories:
- Assistant
Let me look at the dead_code.go file since that's where the dead code analysis logic is likely to be.
- Assistant
Now let me look at the reachability analyzer and the CFG structure:
- Assistant
Now let me look at the CFG structure and the parser to understand how nodes are represented:
- Assistant
Now let me look at the parser to understand what node types exist:
- Assistant
Let me also check the test file for dead code to understand expected behavior better:
- Assistant
Let me first create a reproduction script to understand the issue better:
- Assistant
Let me look at how to run pyscn. Let me check if there's a binary.
- Assistant
Let me check if there's already a built binary or how to build it.
- Assistant
Let me check the Makefile and see how to build.
- Assistant
Let me set GOPATH and GOMODCACHE and build:
- Assistant
I need to set the cache directories properly.
- Assistant
Good, the build succeeded. Now let me run the tool on the repro file to confirm the issue.
- Assistant
Let me check the JSON report:
- Assistant
I've reproduced the issue. Let me see more of the JSON:
- Assistant
I've confirmed the issue. Now let me understand how the CFG builder handles statements:
- Assistant
Let me look at the CFG builder code around line 363 and 384:
- Assistant
The
-needs to be escaped. - Assistant
Let me look at how
raiseis handled in the CFG builder: - Assistant
Let me see how raise is handled:
- Assistant
Now let me look at the
processRaiseStatementfunction: - Assistant
Let me look at the processRaiseStatement function:Similar to processReturnStatement:
- Assistant
Let me look at the processRaiseStatement function:
- Assistant
Now I understand the pattern. The
processRaiseStatement(likeprocessReturnStatement) creates an unreachable block after it. The trailing;creates an empty statement that ends up in this unreachable block. The fix should be in the dead code detector to filter out empty/no-op statements from the findings.Let me understand what the empty statement looks like in the AST:
- Assistant
Let me check how the parser handles trailing semicolons:
- Assistant
Let me check what the AST looks like for a trailing semicolon:
- Assistant
Let me look at the Node structure.
- Assistant
Let me see the Node struct.
- Assistant
Let me check how the parser handles empty statements by looking at the visitor:
- Assistant
Let me look at how the AST builder handles the trailing semicolon and check what the AST node looks like. Let me first check the parser:
- Assistant
Now I understand the issue better. The problem is that
raise ValueError("nope");is parsed as two statements: theraiseand an empty statement (;). When the CFG builder processes the raise, it creates an unreachable block, and the empty statement gets added to that unreachable block.Let me check what the AST looks like for the empty statement:
- Assistant
Let me write a quick test to see what the AST looks like for the trailing semicolon case:
- Assistant
Let me create the debug file within the repository to access internal packages:
- Assistant
Let me check the Location struct:
- Assistant
Let me check the Location struct definition.
- Assistant
Let me update the debug test with the correct field names:
- Assistant
Now I can see the issue clearly. The AST parser represents the trailing
;as a separate node with type literally;. This is a tree-sitter specific representation whereraise ValueError("nope");gets parsed as:Raisenode;node (representing the statement separator / empty statement)
Let me check what the NodeType is for this
;node: - Assistant
The
;is not a defined NodeType. Let me check how tree-sitter represents the semicolon statement in Python. - Assistant
The
;is created directly by the tree-sitter parser. Let me look at how the AST builder creates nodes: - Assistant
Let me look at the AST builder's main buildNode function to see how unknown types are handled:
- Assistant
Let me see what happens with the
;node type. Let me look at the full buildNode function: - Assistant
Now I understand the issue. The
;node falls into thedefaultcase (unhandled types) and creates a generic node with type;. This gets added to an unreachable block after araise/returnstatement.Let me look at the
analyzeDeadBlockmethod more carefully and understand where to add the fix:Now I understand the issue. The;node falls into thedefaultcase (unhandled types) and creates a generic node with type;. Let me look at how the CFG builder handles this node:Now I understand the issue. The;node falls into thedefaultcase and creates a generic node with type;. This gets added to an unreachable block after theraise/returnstatement.Let me look at the
analyzeDeadBlockmethod more carefully and understand where to add the fix:Now I understand the issue. The;node falls into thedefaultcase (unhandled types) and creates a generic node with type;. This gets added to an unreachable block after araise/returnstatement.Let me look at how the CFG builder handles the
;node: - Assistant
Let me look at the switch in the processStatement function around line 476:
- Assistant
Now I understand the full picture. The
;node falls into thedefaultcase of the CFG builder'sprocessStatementand gets added to the unreachable block created after araiseorreturnstatement.Let me look at how the dead code finding is created and where we should filter:Let me understand the flow. When the CFG builder processes the
raisestatement, it creates an unreachable block and setsb.currentBlock = unreachableBlock. Then the next statement (;) gets added to this unreachable block. The dead code detector then reports this block as dead code.The fix should filter out empty/no-op statements from dead code findings. Let me look at the
analyzeDeadBlockmethod more closely and see what I need to modify. - Assistant
Now I understand the issue. Let me implement the fix. The approach is to filter out empty statements (specifically bare
;nodes) from dead code findings. When a block only contains empty statements like;, it should not be reported as dead code. - Assistant
Now I understand the issue and the fix needed. Let me implement it. The approach is to add a helper method to check if a statement is an empty/no-op statement (like a bare
;separator), and then filter out blocks that only contain such statements when generating dead code findings.Let me add the filter in the
analyzeDeadBlockmethod: - Assistant
Let me also check the Location properties for the
;node by looking at the JSON output more carefully: - Assistant
Let me find the function name for building CFGs.
- Assistant
I see, it's
BuildAllnotBuildCFGs. Let me fix the test. - Assistant
Now I can see exactly what's happening. The
;node has Type;and it's in the unreachable block. The fix should filter out blocks that only contain empty/no-op statements (specifically;type nodes).Let me implement the fix in the
analyzeDeadBlockmethod: - Assistant
Now I understand the issue fully. Let me implement the fix. I need to:
- Add a helper function to check if a statement is an empty/no-op statement (bare
;) - In
analyzeDeadBlock, skip blocks that only contain empty/no-op statements
Let me add the helper function and modify
analyzeDeadBlock: - Add a helper function to check if a statement is an empty/no-op statement (bare
- Assistant
Now I need to add the
blockOnlyContainsEmptyStatementshelper method. Let me find a good place to add it: - Assistant
Now I need to add the
blockOnlyContainsEmptyStatementshelper method. Let me add it near the other helper methods:Let me add the helper method near the other block-checking helpers: - Assistant
Now I understand the full picture. Let me implement the fix. I need to:
- Add a helper method to check if a statement is an empty/no-op statement (bare
;) - In
analyzeDeadBlock, skip blocks that only contain empty/no-op statements
Let me add the helper method:
- Add a helper method to check if a statement is an empty/no-op statement (bare
- Assistant
Now I'll implement the fix. I need to:
- Add a helper method to check if a block only contains empty/no-op statements
- Modify
analyzeDeadBlockto skip such blocks
Let me add the helper method after the
blockContainsRaisemethod: - Assistant
Now let me make the changes. First, add the
isEmptyStatementandblockOnlyContainsEmptyStatementshelpers, then modifyanalyzeDeadBlock: - Assistant
Let me use the special
editcommand properly: - Assistant
The edit broke the function structure. Let me see what happened and fix it:
- Assistant
The edit removed the function header. Let me restore the file and redo the edit properly:
- Assistant
Now let me look at the exact line numbers of the function:
- Assistant
Let me see the full function again.
- Assistant
Now let me make the edit carefully, replacing the whole function:
- Assistant
Wait, I need to reconsider. I should NOT include
NodePassinisEmptyStatement. Apassstatement is explicitly written by the developer and could be genuine dead code. The;separator is never intentional dead code - it's just a syntactic artifact.Let me fix the
isEmptyStatementto only check for;: - Assistant
Now let me also update the
DeadBlockscount in theDetectmethod to exclude blocks with only empty statements. Let me check the Detect method: - Assistant
Let me also update the
DeadBlockscount to exclude blocks with only empty statements. I'll modify theDetectmethod to count only blocks that produce actionable findings: - Assistant
The edit broke the code. Let me restore and redo it more carefully:
- Assistant
Let me look at the exact line numbers and make precise edits:
- Assistant
Let me make the edits carefully, one at a time. First, let me update the
Detectmethod: - Assistant
Good, the edit was successful. Now I need to add the helper methods
blockOnlyContainsEmptyStatementsandisEmptyStatement. Let me find the right place:Now I need to add the helper methods. Let me find where to add them: - Assistant
Let me look at the code around line 335:
- Assistant
Now I'll add the two new helper methods after
blockContainsRaise: - Assistant
The code looks good. Now I need to make sure there's a blank line between the
isEmptyStatementfunction and theisSequentiallyAfterfunction. Let me fix that: - Assistant
The code looks good. Now let me test to make sure it compiles and works correctly:Now let me verify the code compiles and test it:
- Assistant
Good, it compiles. Now let me rebuild the binary and test with the reproduction script:
- Assistant
Good, the binary built successfully. Now let me test with the reproduction script:
- Assistant
Excellent! The fix works. The dead code score is now 100/100 with 0 issues. Let me verify by checking the JSON report:
- Assistant
The fix works. The dead code findings are now gone. Let me also make sure the existing tests still pass:Let me also run the existing tests to make sure nothing is broken:
- Assistant
All dead code tests pass. Let me also run a broader set of tests to make sure nothing is broken:Let me run all the analyzer tests to make sure nothing is broken:
- Assistant
All tests pass. Let me also run the full test suite to make sure nothing is broken:Let me run the full test suite to make sure nothing is broken:
- Assistant
All tests pass. Let me also test with some edge cases to make sure the fix handles them correctly. Let me create a more comprehensive test file:
- Assistant
There was a syntax error in the edge_cases.py file (the
;;double semicolon). Let me fix the test file and try again: - Assistant
Let me check the JSON report to see what findings were detected:
- Assistant
The fix is working correctly:
- Trailing semicolons are no longer reported as dead code findings
- Real dead code (like
x = 1afterreturn zin functionh) is still properly detected - The findings for
hfunction correctly showcode: "assignment\nassignment"for lines 14-15 (the real dead code)
Now let me clean up the debug test files:Now let me clean up the debug test files:
- Assistant
Now let me run the full test suite one more time to make sure everything is clean:
- Assistant
All tests pass. Let me verify the changes I made by looking at the diff:Let me verify the changes I made by looking at the diff:
- Assistant
The changes look clean and correct. Let me now go through the checklist:
- Reproduced the issue: Yes - confirmed 2 false positive dead code findings with code=";" and 0-0 column range when running
pyscn analyze --json --no-open semi_repro.py - Confirmed fix resolves the error: Yes - dead code score is now 100/100 with 0 issues after the fix
- Edge cases: Yes - tested with real dead code + trailing semicolons, multiple trailing semicolons, and confirmed real dead code is still properly detected
- Existing tests pass: Yes - all tests pass including
go test ./...
Let me also check if there are any other files that might need updating:
- Reproduced the issue: Yes - confirmed 2 false positive dead code findings with code=";" and 0-0 column range when running
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 →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →