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 analyze the issue:
- The bug is about the dead-code detector reporting trailing semicolons as unreachable code warnings
- When Python code has
raise X;orreturn x;, the trailing;creates an empty statement that is technically unreachable - The fix should skip empty statements (bare
;orpass) when collecting unreachable-branch findings
Let me start by exploring the repository structure to understand the codebase.
Assistant
This is a Go-based project with Python wrappers. Let me look for the dead-code analyzer.
Assistant
Let me find the actual implementation of the dead code analysis:
Assistant
Now I need to find where the unreachable blocks are identified. Let me look at the reachability analyzer:
Assistant
Now I need to understand the
IsEmpty()method onBasicBlockand how statements are represented. Let me also look at the parser to understand how empty statements (trailing semicolons) are parsed:Assistant
So
IsEmpty()only checks if the block has no statements. But the issue is that a trailing semicolon creates a block with an "empty statement" - a statement that exists but is just a;. Let me look at the parser to understand node types:Assistant
I don't see an "Empty" or "Pass" equivalent for empty statements. Let me look at how the CFG builder creates blocks from AST nodes, especially looking for how empty statements (trailing semicolons) are handled:
Assistant
Let me first create a reproduction script to confirm the issue:
Assistant
I've confirmed the bug. The findings show
code: ";",start_column: 0,end_column: 0for both functions. Now let me understand how the CFG builder handles empty statements:Assistant
Let me look at how Python's AST parser handles empty statements. In Python's AST, a trailing semicolon creates an
ast.Passnode or a blank statement. Let me check the parser to see what node type is created:Assistant
Let me look at the AST builder to see how it handles different statement types:
Assistant
Let me create a test script to see what tree-sitter produces for the trailing semicolon case:
Assistant
The internal package can't be imported from outside. Let me write the debug script as a test file inside the package.
Assistant
The AST only shows the Module node. Let me check how the AST builder builds the children:
Assistant
Let me check how the AST builder visits child nodes:
Assistant
Let me look at how the module is built and how statements in it are handled:
Assistant
Let me use tree-sitter directly to see what nodes the parser produces. Let me check how the body is built:
Assistant
Let me update my debug script to print the Body as well:
Assistant
Excellent! Now I can see the issue clearly. The trailing semicolon creates a node with
Type=";"(a literal semicolon type). This is a tree-sitter node type for empty statements. The node hasline=3 col=32-33(for the first one) andline=8 col=12-13(for the second one).Now I need to find where in the code this
;type node is handled and add filtering. Let me check:- Where does this
;node get converted to a CFG statement? - Where should we filter it out?
Let me look at the CFG builder:
- Where does this
Assistant
Let me look at the
processStatementmethod:Assistant
Expression<unique_string>(thought=False)
Assistant
Now let me see the default case in the switch:
Assistant
So the
;node type falls through to thedefaultcase which just adds it to the current block as a statement. Now I understand the issue.The fix should skip empty statement nodes (type
;) when processing statements. Let me check what the node type string is:Assistant
So the
;type is not defined in the AST constants. It comes directly from tree-sitter. Let me define a constant for it and add a filter. Let me check where the best place to filter would be:The best approach is to:
- Define a constant for the empty statement node type in the parser package
- Skip empty statements in the CFG builder's
processStatementmethod
Let me first add the constant:
Assistant
I'll add the empty statement node type constant and then modify the CFG builder to skip it. Let me make the changes:
Assistant
Good. Now let me modify the
processStatementmethod in the CFG builder to skip empty statements:Assistant
Now I'll add a check for empty statements right after the nil check:
Assistant
Wait, I should check for nil first, then check for empty statement. Let me fix the order:
Assistant
I messed up the file. Let me restore it and redo the edit properly:
Assistant
Now let me do the edit properly using the edit command:
Assistant
...
Assistant
Now let me verify the changes build correctly:
Assistant
Let me rebuild the binary and test:
Assistant
The dead code score is now 100/100 with 0 issues. Let me verify the JSON output confirms no dead code findings:
Assistant
The fix works. Now
total_findings: 0and no dead code warnings are emitted. The functions are still analyzed (but no findings since the trailing semicolons are now filtered out).Let me also test some edge cases to make sure the fix is robust:
- Test that real dead code (without trailing semicolons) is still detected
- Test with multiple trailing semicolons
- Test with semicolons after different statement types (break, continue)
Assistant
...
Assistant
The file has syntax errors because of the double semicolons (;;). Let me fix the test file and run individual edge cases:
Assistant
Real dead code is still detected. Let me test more edge cases:
Assistant
...
Assistant
All edge cases pass. Now let me run the existing tests to make sure I haven't broken anything:
Assistant
All analyzer tests pass. Let me also run the parser tests:
Assistant
Let me also run all tests to be thorough:
Assistant
All tests pass. Now let me clean up the debug test file I created:
Assistant
Let me verify the changes I've made:
Assistant
let me run the tests one more time to confirm everything passes after removing the debug test file:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && HOME=/root go test ./... 2>&1 | tail -20 </tool_call>
Assistant
The previous command failed due to a formatting issue. Let me run it again with proper formatting.
Assistant
All tests pass. Let me verify the fix one final time with the original reproduction case:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.