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
I'll start by exploring the repository structure to understand the codebase and locate the dead-code analyzer. Let's first see what's in the current directory.
- Assistant
Let me explore the repository structure more broadly.
- Assistant
This is a Go project. Let me find the dead-code analyzer code.
- Assistant
Let me look at the dead code analyzer and the reachability analysis files.
- Assistant
Now let me look at the reachability analyzer:
- Assistant
Let me also look at the CFG data structures to understand the
BasicBlockandIsEmpty()method: - Assistant
Let me look at the CFG definition.
- Assistant
Let me check the cfg.go file.
- Assistant
Let me see more of this file to understand IsEmpty method.
- Assistant
Let me look at the IsEmpty method and understand what constitutes an empty block.
- Assistant
Let me look at how the parser handles semicolons and empty statements.
- Assistant
Let me look at the parser node types to understand how empty statements are represented.
- Assistant
Let me first create a test file to reproduce the issue:
- Assistant
Now let me try to run pyscn analyze to see if I can reproduce the issue. First, let me check if pyscn is installed.
- Assistant
Need to set up Go environment first.
- Assistant
Need to set HOME.
- Assistant
Now let me run the analyze command on the test file:
- Assistant
I can see 2 dead code issues were reported. Let me check the JSON output:
- Assistant
Great! I can see the issue. The JSON output shows two dead code findings for the semicolons:
{ "code": ";", "reason": "unreachable_branch", "severity": "warning", ... }Now I need to understand how the CFG builder handles semicolons. Let me look at the CFG builder to see how it processes Python code with trailing semicolons.
- Assistant
Let me look at the
processStatementmethod to see how it handles different statement types, including empty statements that come from semicolons. - Assistant
Let me look at the processStatement method.
- Assistant
Let me continue reading to see how NodeExpr is handled further.
- Assistant
Now I understand the issue better. Let me look at how the parser handles semicolons and empty statements. I need to see what node type is created for an empty statement (just a semicolon). Let me search for how semicolons are parsed.
- Assistant
Let me look at the parser code to understand how Python code is parsed.
- Assistant
Let me look at the AST builder to understand how statements are parsed.
- Assistant
Let me search for how the parser handles expression statements.
- Assistant
Let me look at the buildExpressionStatement function.
- Assistant
Let me look at how tree-sitter handles the semicolon. First, let me check if there's a way to see what tree-sitter produces for our test file.
- Assistant
Let me check the parser.go file to understand how parsing works.
- Assistant
Let me understand the AST node types better:
- Assistant
Let me look at the existing dead code tests to understand the testing patterns:
- Assistant
Let me look at the
isTriviamethod in the AST builder to see if semicolons are being filtered. - Assistant
Let me look at the isTrivia method.
- Assistant
Now I need to understand what tree-sitter produces for a Python statement with a trailing semicolon. Let me first check if there's any test infrastructure to help me understand this. Let me look at the AST debug tests.
- Assistant
Let me first understand what tree-sitter produces for a trailing semicolon. Let me create a small test to see the AST structure.
- Assistant
Let me run this from the repository root.
- Assistant
I need to create the test file inside the pyscn directory so it can access the modules.
- Assistant
I need to create the directory first.
- Assistant
Let me create the test file.
- Assistant
I need to run from within the repository directory.
- Assistant
Let me check the Location struct:
- Assistant
Let me look at the Location struct.
- Assistant
Let me fix the test script:
- Assistant
Let me understand the tree-sitter output for the semicolon better:
- Assistant
Now I understand! The tree-sitter parses
raise ValueError("nope");as a block containing two children:raise_statementnode forraise ValueError("nope");node (unnamed) for the semicolon
The
;is a non-named node in tree-sitter. The AST builder processes the block and when it sees the;node, it creates a generic node with Type=;.Let me look at how
buildBlockworks in the AST builder: - Assistant
Now I understand the issue. The tree-sitter parser creates a
;node for the trailing semicolon, which gets added to the AST as a generic node. Then in the CFG builder, this;node ends up in an unreachable block after theraisestatement, and the dead code detector reports it.Let me trace through the CFG builder to understand how this happens:
- Assistant
Let me trace through the CFG builder to understand how the
;node ends up in the unreachable block. - Assistant
Now I understand the issue clearly. Let me look at how the
;node gets added to the block: - Assistant
Now I understand the issue clearly. The tree-sitter parser creates a
;node (unnamed) for the trailing semicolon, which gets added to the AST as a generic node. Then in the CFG builder, this;node ends up in an unreachable block after theraisestatement, and the dead code detector reports it.Now let me look at the dead code test files to understand the testing patterns:
- Assistant
Now let me run the existing tests to make sure they pass before I make changes:
- Assistant
Let me look at how the
;node gets added to the block body in the AST builder: - Assistant
Now I understand the issue. The tree-sitter parser creates a
;node (unnamed) for the trailing semicolon, which gets added to the AST as a generic node. Then in the CFG builder, this;node ends up in an unreachable block after theraisestatement, and the dead code detector reports it.Let me look at how we can filter this out. The most appropriate place is in the
analyzeDeadBlockmethod of the dead code detector. Let me also look at how we can identify empty/no-op statements: - Assistant
Now I understand the issue completely. The problem is that when a trailing semicolon follows a
raiseorreturnstatement, tree-sitter creates a;node that gets added to the AST and then to the CFG. This;node ends up in an unreachable block, and the dead code detector reports it.The fix should be to filter out empty/no-op statements when collecting dead code findings. Let me implement the fix:
- Assistant
Now let me implement the fix. I need to filter out empty/no-op statements when collecting dead code findings. Let me look at the exact location in the dead code detector where findings are created:
- Assistant
Now I understand the issue. The problem is in the
analyzeDeadBlockmethod. When a block contains only empty/no-op statements (like a bare;node), it should be filtered out and not reported as dead code.The fix is to add a check at the beginning of
analyzeDeadBlockto skip blocks that contain only empty/no-op statements. Let me implement this fix: - Assistant
Now I understand the issue. The tree-sitter parser creates a
;node (unnamed) for the trailing semicolon, which gets added to the AST as a generic node. Then in the CFG builder, this;node ends up in an unreachable block after theraisestatement, and the dead code detector reports it.The fix should be to filter out empty/no-op statements when collecting dead code findings. Let me implement the fix:
- Assistant
Now I understand the issue. The tree-sitter parser creates a
;node for the trailing semicolon, which gets added to the AST and then to the CFG. When the dead code detector runs, it finds this;node in an unreachable block and reports it as dead code.The fix is to filter out empty/no-op statements when collecting dead code findings. Let me implement the fix:
- Assistant
I see there's a duplicate. Let me fix that:
- Assistant
I see there's a duplicate comment. Let me fix that:
- Assistant
Good. Let me verify the fix compiles:
- Assistant
Now let me run the existing tests to make sure they pass:
- Assistant
All existing tests pass. Now let me rebuild pyscn and verify the fix with the reproduction case:
- Assistant
Now let me test with the reproduction case:
- Assistant
Let me try a different approach to check the output.
- Assistant
Let me try a different approach - read the JSON file from the reports directory.
- Assistant
Excellent! The dead code score went from 95/100 to 100/100, and the dead code count went from 2 issues to 0 issues. Let me verify by checking the JSON output:
- Assistant
The fix works. The dead code findings for the trailing semicolons are now filtered out. The output shows 0 findings, which is correct.
Now let me run the full test suite to make sure I didn't break anything else:
- Assistant
All tests pass. Let me also run the service-level tests:
- Assistant
All tests pass. Let me also run the reachability tests:
- Assistant
All tests pass. Let me also check the
getBlockCodemethod to see if there's an issue with how it extracts code for;nodes: - Assistant
Let me check the getBlockCode method:
- Assistant
Now let me test some edge cases to make sure the fix works correctly:
- Assistant
The multiple semicolons case caused a syntax error (Python doesn't allow
;;). Let me fix the test file: - Assistant
Excellent! The fix works correctly:
- The trailing semicolons are no longer reported as dead code (0 issues for functions f, g, and h)
- The real dead code in function j (line
x = 1afterreturn v) is still detected (1 issue, 1 critical)
Let me verify by checking the JSON output:
- Assistant
Perfect! The fix works correctly:
- The trailing semicolons are no longer reported as dead code (0 issues for functions f, g, and h)
- The real dead code in function j (line
x = 1afterreturn v) is still detected (1 issue, 1 critical)
Now let me also check if there's an issue with the
0-0column range mentioned in the issue. Let me look at the location information in the JSON output:- The real dead code finding shows
"start_column": 0, "end_column": 0which is the same as the original issue.
Let me check if this is a separate issue or if it's related to how locations are reported. Let me look at the
DeadCodeFindingstructure: - Assistant
Let me check how the service layer converts findings to the domain model:
- Assistant
Let me check the service layer more carefully.
- Assistant
Let me check how the dead code service converts findings to the domain model.
- Assistant
Let me see the full conversion function:
- Assistant
I see the issue. The
DeadCodeLocationin the domain model hasStartColumnandEndColumnfields, but they're not being populated in the conversion function. Let me check the domain model. - Assistant
Let me check the DeadCodeLocation structure:
- Assistant
I see the issue. The
DeadCodeLocationin the domain model hasStartColumnandEndColumnfields, but they're not being populated in the conversion function. Let me check the domain model. - Assistant
The
0-0column range is a separate issue related to theDeadCodeFindingstruct not having column info. The main fix for the trailing semicolon issue is complete.Now let me also verify with the original reproduction case from the issue:
- Assistant
The fix works correctly. The original reproduction case now shows 0 dead code findings, which is the expected behavior.
Now let me run the full test suite to make sure I didn't break anything else:
- Assistant
All tests pass. Let me clean up the test file I created:
- Assistant
Good. Now let me verify the final state of the file and review my changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.