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 this issue:
- The bug is about dead code detection reporting trailing semicolons as unreachable warnings
- In Python,
raise X;parses asraise Xfollowed by an empty statement - The empty statement is technically unreachable, but reporting it is noise
- The fix should skip CFG nodes that correspond to empty statements when collecting unreachable-branch findings
Let me first explore the repository structure to understand how the codebase is organized.
Assistant
I see this is a Rust-based project (
pyscn). Let me look for the Rust source code, which is likely the main implementation.I need to find the dead-code analyzer that reports unreachable branches. Let me explore the structure more.
Assistant
This is a Go-based project. Let me search for the dead-code analyzer.
Assistant
Let me look at the main dead code analyzer file:
Assistant
Let me look at the reachability analyzer to understand how unreachable blocks with statements are determined:
Assistant
Now let me look at the CFG and how blocks and empty statements are handled:
Assistant
Let me look at how the CFG builder handles statements and the parser to understand how empty statements are created:
Assistant
The file is quite long. Let me search for the
processStatementfunction and how empty statements are handled:<tool_call> <function=bash_terminal> <parameter=command> grep -n "processStatement|NodePass|empty|Empty|sempar|semicolon" /pyscn/internal/analyzer/cfg_builder.go </tool_call>
Assistant
Let me search more carefully for how empty statements and semicolons are handled.
Assistant
Let me look at the processStatement function and how it handles NodePass:
Assistant
Let me check how the parser handles semicolons:
Assistant
Let me check what node types exist in the parser:
Assistant
Let me look for the AST builder and how it handles different node types, especially empty statements:
Assistant
Let me look at the AST builder to understand how different node types are mapped.
Assistant
Let me look at the node types to understand what's available:
Assistant
Let me look at the parser node types and understand the issue better.
Assistant
Let me look at the ast.go file to understand the node types:
Assistant
Let me now create a reproduction script and run it to see the actual error:
Assistant
Let me now check the Makefile to understand how to build and run the project.
Assistant
Let me build the project and reproduce the issue:
Assistant
Let me fix the Go environment:
Assistant
The issue is that we need HOME to be set. Let me try a different approach.
Assistant
Good, the build succeeded. Now let me reproduce the issue:
Assistant
Let me check the JSON report:
Assistant
I can now see the bug. Let me see the complete dead_code section:
Assistant
Now I understand the issue. The dead code detector is reporting empty statements (bare
;) as unreachable warnings. Let me understand what node type represents a bare;in tree-sitter:Assistant
The internal package can't be imported from outside the module. Let me create the file inside the project instead.
Assistant
Let me clean up and try another approach - I'll look at the dead code test to understand the node types:
Assistant
Let me look at the dead code test to understand the test structure better:
Assistant
Now I understand the issue. Let me look at how the
expression_statementand semicolons are handled in the parser to confirm what node type represents a bare;:Assistant
Let me look at the
buildExpressionStatementfunction and understand how empty expression statements are handled:Assistant
Now I need to understand where the
";"code string comes from. Let me check the dead code formatter:Assistant
Let me look at how the dead code finding's
codefield gets populated:Assistant
Let me investigate what tree-sitter produces for a bare semicolon:
Assistant
Interesting! There's already some handling for semicolons. Let me look at that:
Assistant
Now I understand the issue. The tree-sitter parser produces a node with type
;for empty statements (bare semicolons). There's already anisLogicalSeparatorfunction to detect this. ThegetNodeDescriptionfunction returnsstring(node.Type)for unhandled node types, so for a;node, it returns;as thecodefield.The fix should filter out empty statements (bare
;/ logical separators) when collecting unreachable-branch findings. Let me implement the fix in theanalyzeDeadBlockfunction indead_code.go:Assistant
Now I understand the issue clearly. The fix should filter out blocks that contain only empty/no-op statements (bare
;which are logical separators) from the unreachable blocks. Let me look at where the filtering happens:Assistant
Now I understand the issue completely. The fix needs to filter out blocks whose statements are only "logical separators" (bare
;nodes with type;). Let me implement the fix.The cleanest approach is to modify
GetUnreachableBlocksWithStatementsinreachability.goto also skip blocks containing only logical separators. These are effectively empty/no-op statements.Assistant
Now let me implement the fix. The issue is that blocks containing only bare
;(logical separators) are being reported as dead code. I need to filter these out. Let me modify theGetUnreachableBlocksWithStatementsfunction inreachability.go:Assistant
Now I understand the issue. The problem is that:
- When a trailing
;follows areturn/raisestatement, tree-sitter creates a node with type; - This creates an "unreachable" block in the CFG
- The
GetUnreachableBlocksWithStatements()function checks if a block is empty viablock.IsEmpty(), but a block containing a;statement is not considered empty - So the
;statement gets reported as dead code
There's already an
isLogicalSeparatorfunction inraw_metrics.gothat detects these;nodes. I need to filter out blocks whose statements are only logical separators.- When a trailing
Assistant
Now I have a clear understanding. The
isLogicalSeparatorfunction already exists in the same package. I need to filter out blocks whose statements are only logical separators (bare;statements).Let me modify the
GetUnreachableBlocksWithStatements()andHasUnreachableCode()functions inreachability.go:Assistant
Let me try using sed to make the changes:
Assistant
Let me try a different approach using a heredoc to write the modified file:
Assistant
Now let me build the project to ensure it compiles correctly:
Assistant
The build succeeded. Now let me test the fix:
Assistant
The fix is working - the dead code score is now 100/100 with 0 issues. Let me verify by checking the JSON report:
Assistant
The fix is working correctly. Now let me run the existing tests to ensure I haven't broken anything:
Assistant
The tests are running. Let me see if all the tests pass.
Assistant
All analyzer tests passed. Now let me run the full test suite to make sure everything works:
Assistant
All tests pass. Let me also test some edge cases to ensure the fix is robust:
Assistant
The double semicolon
;;is a Python syntax error. Let me create a better test:Assistant
Let me check the JSON report to verify that real dead code is still being detected while semicolon-only blocks are filtered:
Assistant
The fix is working correctly:
with_semicolon- NOT reported (correct: semicolons are filtered out)with_real_dead_code- Reportsx = 2as dead code (correct: real dead code)with_pass_after_return- Reportspassas dead code (correct:passis an actual statement, not a bare semicolon)with_mixed- Reports both the semicolon and assignment together (correct: the block contains both, and since it has real code, it's not filtered)
The fix correctly filters out blocks that contain only bare semicolons (logical separators) while still detecting real dead code.
Let me verify the git diff of the changes:
Assistant
The fix is working correctly. Let me now verify my complete checklist:
Assistant
My fix is complete. Let me summarize what I've done and verify the checklist:
Summary of Changes
I modified
/pyscn/internal/analyzer/reachability.goto filter out empty statements (bare;/ logical separators) from dead code findings. The changes:-
Modified
GetUnreachableBlocksWithStatements()- Added a check to exclude blocks whose statements are only logical separators (bare;). -
Modified
HasUnreachableCode()- Added the same filtering to ensure empty-statement-only blocks aren't counted as containing unreachable code. -
Added
blockContainsOnlyLogicalSeparators()helper function - This function checks if a block contains only logical separator statements (bare;), leveraging the existingisLogicalSeparator()function fromraw_metrics.go.
Verification
- Original issue reproduced: ✅ Confirmed the bug with
semi_repro.pyproducing 2 false positive dead code findings - : ✅ The same file now produces 0 dead code findings (score 100/100)
-
Assistant
The user wants me to submit my changes. Let me call the submit command properly.
Assistant
I need to submit my changes. The submit command should be called as a tool call, not as a bash command.
Assistant
The user is telling me that I need to submit my changes. The submit function should be called properly. Let me try again with the correct format.
Assistant
Let me verify my changes are in place first:
Assistant
I've made the changes to fix the issue. The submit command should be called properly now. Let me try again with the correct syntax for the submit function call.
Assistant
I see the issue - the submit tool isn't being invoked correctly. Let me verify the fix is complete and then submit properly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.