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 understanding the repository structure and the issue. The bug is about a dead-code detector that reports empty statements (bare
;) as unreachable warnings, which is noise. I need to find where the dead-code analyzer is and add a filter to skip empty statements.Let me first explore the repository structure.
Assistant
Let me look at the repository structure more carefully, especially focusing on the dead-code analyzer.
Assistant
This is a Go project with a Python component. Let me find the dead-code analyzer code.
Assistant
Let me look at the dead code analyzer to understand how it works.
Assistant
Now let me look at the CFG builder to understand how empty statements are represented:
Assistant
Let me now look at the parser to understand how empty statements are represented:
Assistant
Let me search for how semicolons are parsed, and also look at the reachability analyzer to understand where unreachable blocks are detected.
Assistant
Let me check how the parser handles semicolons and what AST node types exist.
Assistant
Let me look at the reachability analyzer to see where unreachable blocks are detected, and understand the flow better.
Assistant
Let me look at the BasicBlock to understand what
IsEmpty()does and how empty statements are represented:Assistant
Now let me first reproduce the issue by creating the test file and running the analyzer:
Assistant
Let me try to reproduce the issue. I need to understand how to run the tool first.
Assistant
The Go toolchain isn't properly set up. Let me try different approaches.
Assistant
I see there's an issue with the Go module cache. Let me try setting up the environment properly:
Assistant
The environment doesn't have HOME set. Let me fix that.
Assistant
Now let me run the tool to reproduce the issue:
Assistant
Let me check the generated JSON report to see the dead code findings:
Assistant
Let me look at the JSON report directly to understand the structure.
Assistant
I've confirmed the issue. Now let me understand what AST node type these semicolons produce in the parser:
Assistant
Let me place the debug code inside the project so it can access internal packages:
Assistant
Let me look at how the parser is actually used in tests:
Assistant
I see, it's
parser.New(). Let me also check the Node structure to see its actual fields.Assistant
Let me look at the Node structure to understand its fields.
Assistant
Let me fix the debug test:
Assistant
I need to look at how Parse returns the AST - it returns a ParseResult, not a Node directly.
Assistant
Let me fix the test - ParseResult has a RootNode:
Assistant
Now I need to understand the exact AST node types that are generated for the trailing semicolons. Let me fix the debug test to use the correct fields.
Assistant
I see the issue - the context is nil. Let me look at how the parser.New() works and use it correctly with a proper context.
Assistant
Let me look at how tests in the repository create a context for parsing.
Assistant
I need to use
context.Background()when calling Parse. Let me fix the debug test.Assistant
I can see the issue clearly now. The parser creates nodes with
Type = ";"for trailing semicolons. These appear as separate child nodes under the If and Return statements. These are no-op statements that shouldn't be reported as dead code.Let me clean up the debug test and implement the fix:
Assistant
Now I understand the issue clearly. The parser creates AST nodes with
Type = ";"for trailing semicolons. These are no-op statements. When the dead code analyzer runs, it detects these semicolon nodes as unreachable (since they followreturn/raisestatements that terminate the block), and reports them as dead code findings withcode=";"and0-0column range.The fix should be in the dead code analyzer to skip these empty statement nodes. Let me check the exact NodeType value for the semicolon:
Assistant
The fix needs to:
- Add a
NodeEmptytype constant for the semicolon/no-op statement (or check for";"string) - Filter out empty statements in the dead code analyzer
Let me look at the complete list of node types first, then implement the fix.
The best approach would be:
- Add a
NodeEmptyconstant in the parser'sast.gofor the";"type - In the dead code analyzer, skip blocks that only contain empty statements when collecting findings
Actually, looking more carefully at the code:
-
The
GetUnreachableBlocksWithStatements()method inreachability.goalready filters out empty blocks (using!block.IsEmpty()), but the issue is that a block containing ONLY a;node is NOT empty - it has one statement. -
The fix should be in the
analyzeDeadBlockmethod indead_code.go- we should check if a block only contains empty/no-op statements and skip it.
Let me implement the fix by:
- Adding a
NodeEmptyconstant (for the";"semicolon type)
- Add a
Assistant
Now let me implement the fix. I'll add a
NodeEmptyconstant and modify the dead code analyzer to skip empty statements.Assistant
Now I'll add the
NodeEmptyconstant afterNodeContinue(line 42):Assistant
The edit command format is
edit --file PATH LINE_RANGE [REPLACEMENT_TEXT]. Let me try again with the proper format.Assistant
The edit command requires proper indentation. Let me try with the --file option and a different syntax.
Assistant
Let me verify the change was applied correctly.
Assistant
The sed syntax for line ranges is different. Let me use
sed -n '40,46p'instead.Assistant
Good, the
NodeEmptyconstant has been added. Now I need to modify the dead code analyzer to skip blocks that only contain empty statements (trailing semicolons).The fix should be in the
GetUnreachableBlocksWithStatements()method inreachability.go, or I can add a check inanalyzeDeadBlock()indead_code.go. Let me add a helper method toBasicBlockand update the reachability filter:Assistant
I need to add a method to check if a block only contains empty statements (trailing semicolons). I'll add this to the BasicBlock in cfg.go, and then update the
GetUnreachableBlocksWithStatements()method in reachability.go to filter these out.The approach:
- Add
ContainsOnlyEmptyStatements()method to BasicBlock in cfg.go - Update
GetUnreachableBlocksWithStatements()in reachability.go to also check for empty-only blocks
- Add
Assistant
Now I need to add a helper method to check if a block only contains empty statements. Let me add it right after the
IsEmpty()method.Assistant
The edit command format seems to be causing issues. Let me try using the
replacecommand or a different approach.Assistant
I need to add the
ContainsOnlyEmptyStatementsmethod to the BasicBlock in cfg.go. Let me use a different approach - I'll use sed to insert the new method after the IsEmpty method.Assistant
Let me verify the changes were applied correctly and then update the reachability analyzer to use this new method.
Assistant
Good, the method was added successfully. Now I need to update the
GetUnreachableBlocksWithStatements()method inreachability.goto also filter out blocks that only contain empty statements.Assistant
Good, now I need to update this method to also exclude blocks that contain only empty statements. Let me see the current implementation.
Assistant
I need to update this method to also filter out blocks that contain only empty statements. I'll replace the condition
!block.IsEmpty()with!block.IsEmpty() && !block.ContainsOnlyEmptyStatements().Let me also update the
HasUnreachableCode()method which uses a similar check.Assistant
Now I need to update both
GetUnreachableBlocksWithStatements()andHasUnreachableCode()to filter out empty statements. Let me do that with sed.Assistant
Let me update the
GetUnreachableBlocksWithStatements()method to also filter out blocks containing only empty statements:Assistant
Let me verify the changes:
Assistant
Both methods have been updated. Let me verify the full context of the changes:
Assistant
Now let me rebuild and test the fix:
Assistant
Now let me run the tool again to verify the fix:
<tool_call> <function=bash_terminal> <parameter=command> export HOME=/root && export GOPATH=/root/go && export GOMODCACHE=/root/go/pkg/mod && export GOCACHE=/root/.cache/go-build && cd /pyscn && rm -rf .pyscn/reports && ./pyscn_test analyze --json --no-open /tmp/semi_repro.py 2>&1 </tool_call>
Assistant
The user's message contains "ERROR: No tool call was violated." which is an error message from the system. It seems like there was an issue with my last action where I was trying to run the tool but didn't properly format it. Let me re-run the command to test the fix.
Assistant
The fix works! The Dead Code score went from 95/100 (2 issues) to 100/100 (0 issues). Let me verify by checking the JSON report:
Assistant
The fix is working. The dead code findings for trailing semicolons are now filtered out. Let me run the existing tests to make sure nothing is broken:
Assistant
Let me run the full test suite and check specifically for dead code tests:
Assistant
All analyzer tests pass. Let me also run tests for other relevant packages to make sure the changes don't break anything:
Assistant
Let me also run the parser tests and some other tests to ensure the change is comprehensive:
Assistant
All tests pass! Let me verify a few more edge cases to make sure the fix handles them correctly:
Assistant
Let me test these edge cases.
Assistant
The edge cases file had a syntax error. Let me create a simpler test case to verify edge cases work correctly:
Assistant
The fix is working correctly! It detected 1 critical issue - the real dead code (
print("This should still be detected")afterreturn xin f4), while filtering out the trailing semicolons in f1, f2, f3, and f5. Let me verify by checking the JSON report:Assistant
The fix is working correctly. Let me summarize what was changed and verify everything one more time.
Assistant
Let me show the complete diff of the changes I made:
Assistant
All tests pass and the fix works correctly. Let me summarize the changes:
Summary of Changes
-
internal/parser/ast.go: AddedNodeEmptyconstant for the";"(semicolon) node type to have a named constant for empty statements. -
internal/analyzer/cfg.go: AddedContainsOnlyEmptyStatements()method toBasicBlockthat checks if all statements in a block are empty (no-op) statements. These carry no actionable signal and should not be reported as dead code. -
internal/analyzer/reachability.go: Updated bothGetUnreachableBlocksWithStatements()andHasUnreachableCode()to also filter out blocks that contain only empty statements, in addition to filtering out empty blocks.
The fix correctly:
- Filters out trailing semicolons (
;) afterreturn/raise/break/continuestatements - Still detects real dead code (like a
print()statement after areturn) - Handles edge cases (multiple semicolons, semicolons after various terminator statements)
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.