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 what we're working with.
Assistant
Now let's look at the parser module to understand node types and what represents an empty statement.
Assistant
Let me see the full listof node types.
Assistant
Let me look at how the parser builds the AST, especially for trailing semicolons.
Assistant
Let me look at how the parser handles simple statements and check what happens with trailing semicolons.
Assistant
Let me first reproduce the issue.
Assistant
I have reproduced the issue. Now let me trace through the code to understand how the trailing semicolon creates a block.
Assistant
So after a raise statement, an unreachable block is created. Then the body continues to be processed - the empty statement (the trailing
;) becomes the next statement and gets added to this unreachable block.Let me look at the body processingto confirm.
Assistant
Let me confirm what the AST looks like for the issue.
Assistant
Let me see what happens in
processStatementfor unknown types.Assistant
Let me look at how the dead code detector works in detail and understand the full flow.
Assistant
Now let me look at how the getNodeDescription function works and understand the test structure:
Assistant
Let me check how the parser represents the empty statement.
Assistant
So there's no explicit handling of
;in the parser. The;type is being passed through the default case inbuildNode. Let me confirm this by re-reading the AST builder.Looking at the buildNode function:
default: // For unhandled types, create a generic node with children node := NewNode(NodeType(nodeType)) node.Location = b.getLocation(tsNode) ...So
;becomes a NodeType with the value;. Let me verify this in the parser AST:Assistant
Let me look at the dead_code.go file more carefully and look at the test file to understand the structure.
Assistant
Now I have a clear understanding of the issue. Let me make a plan:
Issue Analysis:
- The parser converts
raise X;into two AST nodes: aNodeRaiseand a node with type;(the raw tree-sitter type for empty statement). - After a raise, the CFG builder creates an unreachable block. The empty
;node is added to this block. - The dead-code analyzer reports this block as unreachable with
code: ";".
Fix Plan:
- Add a constant for the empty statement type (
NodeEmptyStatement) in the parser. - Detect
;as an empty statement in the AST builder and create a proper empty statement node. - In the dead-code analyzer's
analyzeDeadBlock, skip blocks that contain only empty statements. - Filter empty statements at the
getNodeDescriptionlevel too so they don't show up as code descriptions.
Let me first verify what node type tree-sitter assigns to the empty statement. Let me also check if we should treat it as
pass-equivalent (no-op).Let me look at the structure of the parser more:
- The parser converts
Assistant
Let me check how
passis handled in the dead code detector:Assistant
Let me look at the tree-sitter output to understand the AST structure better.
Assistant
Now I understand the issue. The
;is a child of theblock(sibling of thereturn_statementorraise_statement), and it's included in the body bybuildBlock. Let me also checkbuildModuleto see if;can appear at the module level too:Assistant
Now I have a clear understanding. Let me implement the fix.
Plan:
- Parser fix: Add a case in
buildNodefor;(empty statement) that returns nil. This prevents;from being added to AST bodies. - Defense in depth: Add filtering in the dead-code analyzer for empty statements.
Let me first check if there are any other places in the codebase that might handle
;nodes:- Parser fix: Add a case in
Assistant
Let me look at the full JSON output to understand all relevant fields:
Assistant
Let me check the service layer to see how the counts are used:
Assistant
Let me check what tests exist for the dead_code module:
Assistant
Let me check all callers of
analyzeDeadBlock:Assistant
Let me check all places that check for the
;type:Assistant
Now I have enough understanding. Let me implement the fix in
dead_code.go:Assistant
Now let me make the fix:
Assistant
Now let me make the actual fix. First, let me modify the
Detect()function to filter out blocks containing only empty statements:Assistant
Now let me apply the edit to the Detect() function:
Assistant
Let me make the edit usingreplace.
Assistant
Now let me add the helper function
blockContainsOnlyEmptyStatementsandisEmptyStatement. Let me find a good location:Assistant
Let me view the area near the other block helper functions and add the new helper functions:
Assistant
The text seems correct but the replace failed. Let me try again with the exact text fromthe file:
Assistant
Now let me also add defense-in-depth filtering in
analyzeDeadBlock:Assistant
Now let me build and test the change:
Assistant
Build succeeded. Let me run the reproducer:
Assistant
The fix works. The "Dead Code" score is now 100/100 (0 issues) instead of 95/100 (2 issues). Let me verify the JSON output too:
Assistant
No findings for the empty statement blocks. Now let me run the existing tests to make sure nothing is broken:
Assistant
All dead code tests pass. Now let me think about edge cases:
Assistant
Let me fix the edge case file to remove syntax errors:
Assistant
raise X;;;is not valid Python syntax. Let me adjust my edge cases:Assistant
A
;on its own line is not valid Python. Let me adjust:Assistant
Let me think about this. The issue specifically mentions
;(trailing semicolons) as the bug. The "Pythonpass-equivalent" is a description of what;is (a no-op likepass), not a separate target. Let me stick with my current fix (only skipping;) and verify the existing tests pass.Let me run all the tests in the analyzer package:
Assistant
All tests pass. Let me also run the parser tests:
Assistant
All tests pass. Let me also clean up my dump_ast command:
Assistant
Now let me also reproduce the exact scenario from the issue and verify it works:
Assistant
Let me verify the fix is complete and review the changes:
Assistant
The diff looks good. Let me also verify the tests pass one more time and run the reproduction case again to make sure the fix is working:
Assistant
All dead-code tests pass. Let me also run the full test suite one more time to make sure nothing else broke:
Assistant
All tests pass. Let me verify the fix one more time using the exact repro from the issue:
Assistant
Let me investigate why
total_functionsis showing as 0:Assistant
Let me check where the JSON output is being formatted:
Assistant
Let me check the JSON formatterfor dead code analysis:
Assistant
Let me check how the dead_code summary is generated:
Assistant
Let me look at the file analysis flow to understand why
files: nullis being output:Assistant
Let me verify my edge cases work correctly:
Assistant
Let me look at where the
start_columnandend_columnare populated:Assistant
The StartColumn and EndColumn are not populated in the conversion function. Let me check theconversion:
Assistant
Let me also improve the
getBlockCodefunction to skip empty statements, so thecodefield is cleaner:Assistant
Now let me also update
getBlockStartLineandgetBlockEndLineto skip empty statements:Assistant
Now let me build and test:
Assistant
The original repro is fixed. Let me also verify the edge cases (mixed case with real dead code):
Assistant
The f2 case now shows just
code="Call"(no;noise). Let me also test all my edge cases:Assistant
Let me now run all tests to ensure nothing is broken:
Assistant
All tests pass. Let me also verify the original repro one more time:
Assistant
The original issue is fixed. Let me view the final diff:
Assistant
Let me clean up the temporary test files:
Assistant
Let me run all the tests one more time to verify everything works:
Assistant
All tests pass. Let me verify the changes one final time by recreating the repro scenario:
Assistant
Both tests work correctly:
- Original repro: 0 issues (the fix correctly removes false positives from trailing semicolons).
- Real dead code: 1 issue detected with
code="Call"(theprint("dead code")call, with no;noise).
Let me clean up temporary files:
Assistant
Only one file is modified. Let me verify the diff onemore time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.