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):pythondef f(x): if x is None: raise ValueError("nope"); return x def g(y): return y;Run:
bashpyscn analyze --json --no-open semi_repro.pyActual output
Two dead-code findings (from the generated JSON report):
json{"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 — a that points at literal with a column range reads as a real defect when there is none. Bounded impact: only fires on the rare trailing-semicolon style.
Assistant
I'll start by exploring the repository structure to understand the codebase and find the relevant dead-code analyzer.
Assistant
This is a Go-based project with some Python wrapper. Let me explore the structure more to find the dead-code analyzer.
Assistant
Good! Let me look at the dead code analyzer files, starting with the main analyzer:
Assistant
Now let me look at the reachability analyzer to understand how it gets unreachable blocks with statements:
Assistant
Now let me look at the
IsEmptymethod and the BasicBlock structure:Assistant
Now let me look at the parser.Node structure to understand what node types exist:
Assistant
Now let me check if there's a NodeEmptyStmt or similar:
Assistant
Looking at the grep results, there's no NodeEmptyStmt in the parser. Let me check what Python's AST produces for an empty statement (the trailing semicolon). Let me look at the ast_builder.go to see how it handles this.
Assistant
Let me first reproduce the issue by creating the test file and running the analysis:
Assistant
The user is pointing out that my function call format was incorrect. I need to use the proper bash_terminal function format. Let me continue by running the analyze command to reproduce the issue.
Assistant
Let me check how to run pyscn:
Assistant
This is a Go project. Let me check if there's a Go binary I can use:
Assistant
Great! The build succeeded. Now let me test the repro:
Assistant
I need to see the JSON output to confirm the bug. Let me check the report file.
Assistant
Perfect! I've confirmed the bug. I can see the two findings:
- Function
f: line 3, code";", reason "unreachable_branch", severity "warning", withstart_column: 0, end_column: 0 - Function
g: line 8, code";", reason "unreachable_branch", severity "warning", withstart_column: 0, end_column: 0
Now I need to understand how these empty statements (trailing semicolons) are being parsed. Let me check the Node structure:
- Function
Assistant
Now let me check what node type the empty statement is. Let me look at how the CFG builder processes statements:
Assistant
Let me look at what Python's AST produces for a trailing semicolon. In Python, a trailing semicolon creates an
Passnode. Let me verify by checking how the CFG builder handles statements:Assistant
Let me check the Location structure to understand the 0-0 column range issue:
Assistant
Now let me check what the actual node type is for an empty statement (trailing semicolon). Let me write a small test to see what node type is generated:
Assistant
...exit_code<<0 EOF
<tool_call> ...command<<export HOME=/root && export GOPATH=/root/go && export GOMODCACHE=/root/go/pkg/mod && export GOCACHE=/root/.cache/go-build && cd /pyscn && go run /tmp/test_parse.go ...
Assistant
The user's response indicates I need to use the proper tool call format. Let me run the test script I created.
However, looking at my previous output, I see I tried to use special markers that aren't valid. Let me just run the command properly.
Actually, wait - I see the system is telling me that no tool call was invoked. This means I need to use the proper function calling syntax. But I don't see any functions defined in the system prompt.
Looking at the conversation history, I see I've been using ````bash_command` blocks successfully before. Let me try that again with the correct command.
Actually, I think the issue is that I started typing a command but didn't complete it properly. Let me start fresh.
Assistant
I can't use internal packages from outside the module. Let me create the test file inside the pyscn directory structure instead.
Assistant
The user is asking me to respond with my full thoughts. I was in the middle of investigating the bug where trailing semicolons in Python code are being reported as dead code findings. I had just created a test file to understand what node type is generated for empty statements.
Let me continue my investigation by running the test file I created to see what node types are generated for the trailing semicolons.
Assistant
The user is showing me the output from my previous command attempt which failed. I need to check what the correct way to create a parser is in this codebase.
Assistant
The user is showing me that
parser.NewParserdoesn't exist - the correct function isparser.New(). Let me fix my test script and try again to understand what node type is generated for trailing semicolons.Assistant
The user is showing me that my previous command to create the test file succeeded. Now I need to run it to see what node types are generated for the trailing semicolons. Let me execute the test file.
Assistant
The user is showing me compilation errors. I need to check the correct API for the parser. Let me look at the parser.go file to understand the correct function signatures.
Assistant
The user is showing me the parser.go file. Now I understand the API better:
parser.New()creates a new parserparser.Parse(ctx context.Context, source []byte)parses code- It returns a
*ParseResultwhich has anAST *Nodefield
Let me update my test script with the correct API. I need to:
- Import context
- Use
ctx context.Contextas the first parameter - Access the AST via
result.AST
Let me fix my test script.
Assistant
The user is showing me that the test file was created successfully. Now I need to run it to see what node types are generated for the trailing semicolons.
Assistant
The user is showing me the output of my test script. I can see that the trailing semicolon is being parsed as a node with type
;(a literal semicolon character) at line 3, column 32-33. This is the empty statement that's being reported as dead code.Now I understand the issue:
- The trailing semicolon creates a node with type
; - This node has location
line 3, col 32-33(which is where the semicolon is in the source) - When the raise statement terminates the block, this
;node becomes unreachable - The dead code analyzer reports it as a finding with code
";"
Now I need to check if there's a constant for this node type. Let me search for it.
- The trailing semicolon creates a node with type
Assistant
The user is showing me that my grep command didn't find any NodeType constant for the semicolon. This means the
;node type is likely defined dynamically by tree-sitter, not as a constant in the codebase.Let me check how the AST builder handles this semicolon node. I need to look at the AST builder to see how it converts tree-sitter nodes to internal nodes.
Assistant
This is a very long output showing various loop patterns and field access patterns in the ast_builder.go file, but nothing specific about empty statements or semicolons. Let me search more specifically for how empty statements or the
;node type is handled.Assistant
// TODO: move this to ast.go or parser.go
Assistant
The user is telling me that I need to use a structured tool call with a function name and arguments. Looking at the system prompt, I can see there's a
bash_terminalfunction available. I was trying to make a note to myself but the system interpreted it as a command.Let me continue investigating by looking at the switch statement in the ast_builder.go file to see how different node types are handled, particularly looking for empty statements.
Assistant
Perfect! I can see that the default case creates a generic node for unhandled types, which means the
;is being treated as a node type. Now I need to understand the solution. Let me check how the dead code detector analyzes blocks:Assistant
Let me continue investigating the issue. I need to look at the
analyzeDeadBlockfunction to understand where to add the filter for empty statements.Assistant
The user is showing me the
analyzeDeadBlockfunction. This is where I need to add the filter for empty statements. Looking at the code:- The function checks if the block is nil or has no statements
- It determines the reason and severity
- It creates a finding for the dead block
According to the issue description, I need to skip CFG nodes that correspond to empty statements (the no-op produced by a trailing
;). The suggested fix is to filter out empty statements when collecting unreachable-branch findings.I have two options:
- Add a check in
analyzeDeadBlockto skip blocks that only contain empty statements - Add a check in
GetUnreachableBlocksWithStatementsto filter out blocks with only empty statements
Looking at the code, I think the best approach is to add a helper method to check if all statements in a block are empty statements (semicolons), and then skip such blocks in .
Assistant
The user is showing me the output of the
sedcommand. I can see thegetNodeDescriptionfunction. Let me look at the rest of it to see what it returns for different node types, including what it might return for an empty statement (semicolon).From the code I can see:
getBlockCodecallsgetNodeDescriptionfor each statement in the blockgetNodeDescriptionhas a switch statement that handles different node types
From my earlier investigation, I know that the semicolon node type is
";"(a literal semicolon). Since it's not explicitly handled in the switch statement, it would fall through to the default case which returnsstring(node.Type), which would be";".Now I need to implement the fix. The best approach is to:
- Add a helper method to check if a statement is an empty statement (semicolon)
- Modify
analyzeDeadBlockto skip blocks that only contain empty statements
Let me look at the rest of
getNodeDescriptionto confirm my understanding.Assistant
The user sent an empty message. I should continue with my investigation and implement the fix.
Based on my investigation so far, I understand the issue:
- When Python code has a trailing semicolon after a
raiseorreturnstatement (e.g.,raise X;), it parses as two statements: theraisestatement followed by an empty statement (the semicolon) - The empty statement is represented as a node with type
";"(literal semicolon character) - When the CFG is built, this empty statement becomes its own basic block
- The dead code analyzer marks this block as unreachable (which is technically correct)
- The dead code detector reports this as a finding with code
";"and a 0-0 column range
The fix should be to filter out blocks that only contain empty statements when creating dead code findings.
Let me now implement the fix in the
analyzeDeadBlockfunction.- When Python code has a trailing semicolon after a
Assistant
The user sent an empty message again. I should verify that my fix was applied correctly and then test it to make sure it resolves the issue.
Let me check if the changes were applied correctly to the dead_code.go file.
Assistant
Good! My fix has been applied successfully. I can see:
- The
analyzeDeadBlockfunction now callsisBlockOnlyEmptyStatementsto skip blocks with only empty statements - The new
isBlockOnlyEmptyStatementshelper method checks if all statements in a block are empty statements (type";")
Now I need to rebuild the binary and test it against the reproduction case.
- The
Assistant
Great! The build succeeded. Now let me test the fix by running the analyzer on the reproduction case.
Assistant
Excellent! The fix works! I can see that:
- Before the fix: Dead Code score was 95/100 with 2 issues
- After the fix: Dead Code score is 100/100 with 0 issues
The trailing semicolon empty statements are no longer being reported as dead code findings. Let me verify by checking the JSON report to confirm there are no dead code findings.
Assistant
Perfect! The JSON report confirms that there are now 0 findings (previously there were 2). The fix is working correctly.
Now let me think about edge cases and test them:
Edge Cases to Consider:
- Multiple trailing semicolons - e.g.,
raise X;; - Semicolons in other contexts - e.g., multiple statements on one line like
x = 1; y = 2 - Semicolons after break/continue - Similar pattern
- Mixed blocks - A block with both real statements and empty statements
- Pass statements - Should NOT be filtered (they're intentional)
Let me create a comprehensive test to verify these edge cases:
- Multiple trailing semicolons - e.g.,
Assistant
The user sent an empty message. I should continue testing my fix with the edge cases I just created to make sure it handles them correctly.
Let me run the analyzer on the edge cases file to verify the fix handles all scenarios correctly.
Assistant
The file has syntax errors (double semicolons). Let me fix the test file:
Assistant
The user sent an empty message. Let me run the analyzer on the corrected edge cases file to verify the fix handles all scenarios correctly.
Assistant
The user sent an empty message. I see the analysis completed but I notice that Dead Code shows 100/100 with 0 issues. However, I expected test case 4 (real dead code with
print("This is dead code")) to be detected. Let me check the JSON report to see if it was detected or if there's an issue with my test case.Actually, looking at test case 4 more carefully, the
printstatement comes AFTER theraisebut BEFORE thereturn. So it's actually reachable code! Let me fix my test case to properly test real dead code.Assistant
The user sent an empty message again. Let me run the analyzer on the corrected edge cases file to verify that:
- Empty statements (semicolons) are filtered out
- Real dead code is still detected
Assistant
Good! Now I can see Dead Code: 95/100 (1 issues, 1 critical). This is the real dead code from test case 4 or 5. Let me check the JSON report to see which one was detected and confirm that the semicolon cases were filtered out.
Assistant
The user is showing me the JSON report. I can see that:
- Only 1 dead code finding was detected - the
print("This is dead code")after thereturnstatement intest_real_dead_code_after_return - No findings for the semicolon cases (test_semicolon_after_raise, test_semicolon_after_break, test_semicolon_after_continue)
- Real dead code is still being detected correctly
This confirms that my fix is working correctly:
- ✅ Empty statements (semicolons) after terminating statements are filtered out
- ✅ Real dead code is still detected
- ✅ The fix doesn't break existing functionality
Now let me run the existing tests in the repository to make sure I didn't break anything.
- Only 1 dead code finding was detected - the
Assistant
The user sent an empty message. I see that all tests pass! Let me now clean up the temporary test file I created and verify the fix one more time with the original reproduction case.
Assistant
The user sent an empty message. I should continue with the verification process. Let me test the original reproduction case one more time to confirm the fix works, then I'll submit.
Assistant
Checklist Review
Let me go through each bullet from the checklist:
-
If an error was reported in the issue description, I have successfully reproduced it.
- ✅ DONE: I created the
semi_repro.pyfile with the exact code from the issue description and ranpyscn analyze --json --no-open semi_repro.py. The output showed 2 dead-code findings with code";", reasonunreachable_branch, severitywarning, and column range0-0, exactly as reported in the issue.
- ✅ DONE: I created the
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.