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 a dead-code detector reporting empty statements (bare
;) as unreachable code - When Python code has a trailing semicolon like
raise ValueError("nope");, it parses asraise Xfollowed by an empty statement - The empty statement is technically unreachable, but reporting it as a warning is noise
- The fix should skip CFG nodes that correspond to empty statements when collecting unreachable-branch findings
Let me start by exploring the repository structure to understand the codebase.
- The bug is about a dead-code detector reporting empty statements (bare
Assistant
Let me explore the repository structure more to understand the project layout.
Assistant
This is a Go project with Python tooling. Let me explore the internal directory since it likely contains the dead code analyzer.
Assistant
Found the key files. Let me look at the dead_code.go file:
Assistant
Now let me look at the reachability.go file to understand how unreachable blocks are determined:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/internal/analyzer/reachability.go </tool_call>
Assistant
Let me run the command properly.
Assistant
Now let me look at the CFG structure to understand
BasicBlockand theIsEmpty()method:Assistant
Let me look at the cfg.go file to understand BasicBlock and how empty blocks are defined:
Assistant
Let me look at the parser to understand how empty statements (bare
;) are represented:Assistant
Now I need to understand the core issue. Looking at the code:
-
The
GetUnreachableBlocksWithStatements()method inreachability.gofilters blocks using!block.IsEmpty(). -
But
IsEmpty()returnslen(bb.Statements) == 0- only returns true if there are NO statements at all. -
The issue is about empty statements (bare
;) that ARE in the block but are empty statements. These would havelen(bb.Statements) > 0but they're essentially no-ops. -
The problem is that the dead code analyzer is reporting these empty statements (the
;afterraise X;) as unreachable code.
Let me look at the AST node types to understand how empty statements are represented:
-
Assistant
Now I understand the structure. Let me first reproduce the issue by creating the test file and running the analyzer:
Assistant
Let me now figure out how to run the analyzer. Let me check how
pyscn analyzeworks.Assistant
Let me check how to run the tool:
Assistant
Let me fix the Go environment first:
Assistant
It seems like the shell commands are executing but the output might be getting cut off or something. Let me try a simpler approach - just run the command and see what happens.
Assistant
Let me set up the Go environment properly:
Assistant
Now let me reproduce the issue by running the tool on the test file:
Assistant
Let me check the generated JSON report:
Assistant
The user wants me to check the generated JSON report to see if the bug is reproduced. Let me cat the file.
Assistant
Good, I can see the bug is reproduced (2 warning findings). Let me get the exact JSON output to verify:
Assistant
I've confirmed the bug is reproduced. Now let me understand how the CFG builder handles empty statements:
Assistant
Let me understand what node type is created for a bare
;:Assistant
The standard Python AST doesn't show the semicolon. Let me understand how tree-sitter represents it:
Assistant
Let me look at how
processStatementhandles statements, particularly looking for how trailing semicolons might be processed:Assistant
Now let me look at how the
processStatementfunction handlespassstatements and how it adds statements to blocks:Looking at the issue:
- When a trailing
;is encountered afterraise Xorreturn Y, tree-sitter creates an empty;as a separate node. - This empty node ends up in a block with no content (or very minimal content).
- The
IsEmpty()check inGetUnreachableBlocksWithStatements()only checks if the block has no statements at all. - But in this case, the block DOES have statements - they're just empty/no-op statements (like bare
;).
The fix should be:
- Filter out blocks that only contain empty/no-op statements before reporting them as dead code.
- Or, filter out the specific findings that correspond to empty statements.
Let me understand how the dead code finding gets the
codefield set to;. Looking at the function in :- When a trailing
Assistant
Let me understand the flow:
processStatementis called for each statement- For statements like
raiseandreturn, it creates a block terminator - After a terminator, the code likely creates a new block
- The empty
;(semicolon) statement ends up in that new block
Let me look at the full
processStatementfunction and how it handles raise/return statements.Assistant
I see the issue. After a
returnstatement, the CFG builder creates an unreachable block and sets it as the current block. If there's a trailing;(semicolon), it gets added to this unreachable block. That's why the dead code detector finds it.Let me continue reading the code to see how
raisestatements are handled.Assistant
Let me look at how
raisestatements are handled in the CFG builder.Assistant
Let me find the
processRaiseStatementfunction:Assistant
Let me see the
processRaiseStatementfunction:Assistant
Now I have a clear understanding of the issue:
- When Python code has
raise X;orreturn Y;, tree-sitter parses this as the main statement (raise X/return Y) followed by an empty statement (bare;). - After a
raiseorreturn, the CFG builder creates an "unreachable" block, and the bare;statement gets added to this block. - The
GetUnreachableBlocksWithStatements()method filters out blocks whereIsEmpty()returns true (no statements), but a block with only a bare;has one statement, so it's not filtered out. - The dead code detector then reports this unreachable block as a finding.
The fix should filter out blocks that only contain "empty" statements (like bare
;). Let me implement this:- When Python code has
Assistant
Let me understand the structure better. I'll add a helper function to detect empty statements and filter them out in the dead code detector. First, let me look at what the
getNodeDescriptionfunction does for unrecognized node types:Assistant
Now I understand the issue fully. Let me implement the fix. The solution is to filter out blocks that only contain "empty" statements (like bare
;) in the dead code detector. I'll add a helper function and use it inanalyzeDeadBlock.Let me first verify my understanding by looking at the test file for dead code:
Assistant
Now I understand the issue completely. The fix should filter out blocks that contain only empty statements (like bare
;). I'll add a helper function to detect "empty" statements and use it in the dead code detector.Let me implement the fix:
Assistant
Now I have a clear understanding of the issue. Let me implement the fix. I'll add a helper function to detect empty statements and filter them out in the dead code detector.
Assistant
Let me create a test script to verify the node type of bare semicolons:
Assistant
Let me create the test file within the repository to access internal packages:
Assistant
Let me create a test file within the analyzer package:
Assistant
Let me check how to properly use the parser:
Assistant
The issue is that
parser.NewParser()doesn't exist - the correct function isparser.New(). But it requires a context. Let me update the test.Assistant
The field is
AST, notAst. Let me fix the test.Assistant
Now I understand the issue perfectly. The debug test confirms:
- For function
f, blockbb5(unreachable_4) contains only a;statement (the trailing semicolon) - For function
g, blockbb3(unreachable_2) contains only a;statement
The fix is to filter out blocks that only contain empty statements (like bare
;) in the dead code detector. I'll add a helper function to detect "empty" statements and use it to filter them out.Let me implement the fix in
dead_code.go:- For function
Assistant
Now I understand the issue perfectly. The debug test confirms:
- Block
bb5in functionfcontains only a;statement (the trailing semicolon) - Block
bb3in functiongcontains only a;statement
The fix is to filter out blocks that only contain empty statements (like bare
;) when collecting dead code findings. I'll implement this by:- Adding a helper function
isBlockOnlyEmptyStatementsto detect if a block only contains empty statements - Using this helper in the dead code detector to skip such blocks
- Block
Assistant
Let me implement the fix. I'll add a helper function to detect empty statements and filter them out in the
GetUnreachableBlocksWithStatements()method:Assistant
Now I have a clear understanding of the issue. I need to fix the
GetUnreachableBlocksWithStatements()method inreachability.goto filter out blocks that only contain empty statements (like bare;). Let me implement the fix.Assistant
Now I'll implement the fix. I need to modify the
GetUnreachableBlocksWithStatements()method inreachability.goto filter out blocks that only contain empty statements (like bare;).Assistant
Let me try again with the proper edit format.
Assistant
Let me use a different approach - I'll use
sedto edit the file:Assistant
Let me write a Go script to perform the edit:
Assistant
Let me verify the changes were applied correctly.
Assistant
Let me verify the changes compile correctly and test the fix.
Assistant
The code compiles successfully. Now let me verify the fix works by running the analyzer again on the test file.
Assistant
I need to check if the fix resolved the issue. Let me check the JSON report to see if the empty statement findings are now filtered out.
Assistant
The fix didn't work because the binary I'm running is the old one. I need to rebuild it.
Assistant
The fix is working! The dead code score improved from 95/100 to 100/100, and it now shows "0 issues" instead of "2 issues". Let me verify by checking the JSON report:
Assistant
The fix is working perfectly! The dead code findings dropped from 2 to 0, and the dead code score went from 95 to 100. Now let me run the existing tests to make sure I haven't broken anything.
Assistant
All dead code tests pass! Let me also run the reachability tests to make sure the fix works correctly:
Assistant
All reachability tests pass as well. Let me run all analyzer tests to make sure nothing is broken:
Assistant
All tests pass. Let me now verify the fix handles edge cases properly. I'll test a few more scenarios:
Assistant
Let me check the edge cases more carefully to ensure the fix handles them properly:
Assistant
The issue says the syntax error is found, which means some edge cases have syntax errors. Let me fix the edge cases file and re-test. The file had syntax errors due to invalid Python code patterns like
pass;which is actually valid Python butreturn x;;might not be.Let me create a cleaner edge case file with valid Python that uses trailing semicolons.
Assistant
Let me verify the fix is working correctly for the edge case where there IS real dead code (not just trailing semicolons):
Assistant
The fix is working correctly. Real dead code (like
print("This is truly dead code")) is still being reported, while empty statements (bare;) are being filtered out. Let me verify this by checking the JSON report.Assistant
Excellent! The fix is working correctly. Real dead code is still being reported, while empty statements are filtered out. Let me run the full test suite to ensure nothing is broken:
Assistant
All tests pass. Let me view the final state of the modified file to ensure it's correct:
Assistant
The fix is complete and verified. Let me provide a summary of the changes made:
Summary
Issue: The dead-code detector was reporting bare semicolons (
;) afterreturn/raisestatements as unreachable dead code. These are no-op statements with a0-0column range that provide no actionable signal.Root Cause: When Python code has trailing semicolons like
raise ValueError("nope");, tree-sitter parses this as the main statement (raise X) followed by an empty statement (bare;). The CFG builder creates an "unreachable" block for code after terminators, and the bare;ends up in that block. TheGetUnreachableBlocksWithStatements()method was only filtering out truly empty blocks (no statements), but not blocks containing only empty statements.Fix: Added two helper functions and modified
GetUnreachableBlocksWithStatements():isEmptyStatement()- detects if a node represents an empty statement (bare )
Assistant
The fix is complete and verified. Let me submit the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.