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 problem is that the dead-code detector reports trailing semicolons as unreachable code
- In Python, a trailing
;after areturn/raisestatement creates an empty statement - This empty statement is technically unreachable, but reporting it as dead code is noise
- The fix should filter out empty statements when collecting unreachable-branch findings
Let me start by exploring the repository structure to understand the codebase.
Assistant
This looks like a Go-based project with Python integration. Let me first reproduce the issue as described in the issue.
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && cat semi_repro.py << 'EOF' def f(x): if x is None: raise ValueError("nope"); return x
def g(y): return y; EOF </tool_call>
Assistant
Let me create the reproduction file and then run the analyze command.
Assistant
Now let me run the analyze command to reproduce the issue:
Assistant
I need to build the project first. Let me check what build system it uses.
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && cat Makefile | head -50 </tool_call>
Assistant
I need to use a proper tool call for bash commands.
Assistant
I need to set up the Go module cache before building. Let me first check the environment and set up GOPATH/GOMODCACHE.
<tool_call> <function=bash_terminal> <parameter=command> export GOPATH=/root/go && export GOMODCACHE=/root/go/pkg/mod && cd /pyscn && make build 2>&1 </tool_call>
Assistant
Let me run the command properly with proper quoting.
Assistant
I need to set more environment variables for Go to work. Let me set HOME and GOCACHE as well.
Assistant
Build succeeded. Now let me reproduce the issue:
Assistant
The analysis succeeded. Now let me check the JSON report to see the dead-code findings:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && cat .pyscn/reports/analyze_20260721_164208.json | python3 -m json.tool </tool_call>
Assistant
Let me use bash_terminal for the JSON command.
Assistant
I've confirmed the issue - the report shows two dead-code findings with
"code": ";"and column range0-0. Now let me find the dead-code analyzer in the Go codebase.Assistant
Let me look at the dead code analyzer to understand where the findings are generated:
Assistant
Now let me look at the
analyzeDeadBlockfunction. The issue is that empty statements (bare;semicolons) are being reported as dead code. The fix should be to filter out empty statements before generating findings.Looking at the
analyzeDeadBlockfunction:func (dcd *DeadCodeDetector) analyzeDeadBlock(block *BasicBlock) []*DeadCodeFinding { var findings []*DeadCodeFinding if block == nil || len(block.Statements) == 0 { return findings } ...The issue is that when a trailing semicolon exists, it creates a block with an empty statement (a
;node). This statement is technically unreachable but it's not meaningful dead code.Let me look at the
getBlockCodefunction to see how it extracts code. It usesgetNodeDescriptionwhich should return ";" for empty statements.The fix should filter out empty statements from findings. Let me check what the statement type is for a bare
;:<tool_call> <function=bash_terminal> <parameter=command> grep -r "NodeEmpty|NodePass|empty" /pyscn/internal/parser/*.go 2>/dev/null | head -30 </tool_call>
Assistant
Let me search for how empty statements or semicolons are parsed.
Assistant
Let me understand the AST types in this parser better. I need to see what type a trailing
;gets parsed as:<tool_call> <function=bash_terminal> <parameter=command> grep -r "NodeType|type.*Node" /pyscn/internal/parser/ast.go | head -40 </tool_call>
Assistant
Let me search more specifically for the AST node type definitions:
Assistant
Let me understand how trailing semicolons are parsed. I need to see what happens when Python parses
raise X;:<tool_call> <function=bash_terminal> <parameter=command> find /pyscn -name "*.go" -exec grep -l "expr_statement|semicolon|;" {} ; 2>/dev/null | head -10 </tool_call>
Assistant
I need to find how the parser handles trailing semicolons. Let me look at the parser code more carefully.
Assistant
Let me look at the AST builder to see how nodes are created.
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/internal/parser/ast_builder.go | head -150 </tool_call>
Assistant
Let me try to understand how the parser works by looking at more of the code. Let me look at what Node type a bare semicolon would be parsed as.
Assistant
Let me look at how statements get parsed and what happens with trailing semicolons. The issue mentions that
raise X;is parsed asraise Xfollowed by an empty statement. In Python's AST, this would likely be anExprnode that's empty.Assistant
Let me check the AST builder to understand how statements are parsed:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "ExprStatement|statement|stmt" /pyscn/internal/parser/ast_builder.go | head -30 </tool_call>
Assistant
The grep command didn't return output. Let me try a different approach - looking at the ast_builder.go file directly:
Assistant
This file is large. Let me search for how statements are parsed:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "func build.*Statement|func build.*Stmt|pass_statement" /pyscn/internal/parser/ast_builder.go </tool_call>
Assistant
Let me try a different approach. Let me look at how the parser works by examining the visitor.go file that was mentioned earlier:
Assistant
Looking at the visitor.go file, I can see that the
SimplifierVisitorremovesNodePassstatements. This tells me thatpassis one of the types of empty/no-op statements.Now let me understand how trailing semicolons are parsed. In Python, a trailing semicolon like
raise X;is parsed asraise Xfollowed by an empty statement. In Python's AST, an empty expression statement (a bare semicolon) is typically represented as anExprnode with a nil value or anExprnode with aNonevalue.Let me look at the dead_code.go file again and focus on the
analyzeDeadBlockfunction to see where I need to add the filtering:The key insight from the issue is that we need to filter out empty statements (bare
;semicolons) from dead code findings. Looking at thegetNodeDescriptionfunction, it doesn't handleNodeExprspecifically, so a bare semicolon would fall through to the default case and returnstring(node.Type)which would be "Expr".Assistant
I need to use proper bash_terminal syntax for my command. Let me search for how empty statements are handled in the AST builder.
Assistant
Let me look at the context around line 798 in ast_builder.go to see how NodeExpr is created:
Assistant
I see! The empty expression statement (bare semicolon) is created at line 798 in the
buildExpressionStatementfunction (or similar). It returns aNodeExprwith no children.Now I need to understand what makes a NodeExpr represent an empty statement (bare semicolon). Let me look at the function that calls this:
Assistant
Now I understand. When there's a trailing semicolon,
buildExpressionStatementreturns aNodeExprwith no children (empty expression statement). The fix should filter out emptyNodeExprnodes from the dead code findings.Let me look at the
getNodeDescriptionfunction and thegetBlockCodefunction more closely to understand how to filter these out:Assistant
Now let me look at the
getNodeDescriptionfunction:<tool_call> <function=bash_terminal> <parameter=command> sed -n '425,465p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
I need to use a proper bash command to get the line numbers for getNodeDescription.
Assistant
Now I understand the issue better. The
getNodeDescriptionfunction returns "expression" forNodeExpr, but the issue shows"code": ";"in the output. This means the actual code content is extracted differently, possibly from the raw source.Let me look at how the code content is extracted. Looking back at the issue output, the code is literally ";" with column 0-0. This suggests the code is extracted from the source, not from the description.
Let me check the reachability analyzer to see where the code is extracted from:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/internal/analyzer/reachability.go </tool_call>
Assistant
I need to use a proper bash_terminal command to read the file.
Assistant
Now I see the
GetUnreachableBlocksWithStatementsfunction at line 137. It filters out empty blocks usingblock.IsEmpty(). Let me check whatIsEmpty()does:<tool_call> <function=bash_terminal> <parameter=command> grep -n "IsEmpty|func.*Empty" /pyscn/internal/analyzer/cfg.go | head -20 </tool_call>
Assistant
I need to find the IsEmpty function definition for BasicBlock. Let me search for it.
Assistant
Let me look at the IsEmpty function:
Assistant
Now I understand the issue. The
IsEmpty()function checks iflen(bb.Statements) == 0, but a trailing semicolon creates an empty statement (NodeExpr) that still counts as a statement. The fix should filter out blocks that contain only empty expression statements (NodeExpr with no meaningful content).Let me check the BasicBlock structure to understand how statements are stored:
Assistant
Let me look at the BasicBlock structure:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '63,135p' /pyscn/internal/analyzer/cfg.go </tool_call>
Assistant
Let me use proper bash_terminal to get the lines from cfg.go
Assistant
Now I understand the structure. A BasicBlock has a slice of
*parser.Nodefor statements. A trailing semicolon creates aNodeExprwith no children/value.The fix should be in the
analyzeDeadBlockfunction in dead_code.go. We need to filter out blocks that contain only empty expression statements (bare semicolons).Let me look at the
analyzeDeadBlockfunction again and determine the best place to add the filtering:<tool_call> <function=bash_terminal> <parameter=command> sed -n '195,240p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
I need to use bash_terminal properly. Let me get the analyzeDeadBlock function.
Assistant
Let me search for the full analyzeDeadBlock function:
Assistant
Now let me see the full analyzeDeadBlock function starting from line 190:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '190,220p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
I need to use bash_terminal with proper syntax. Let me try again with the right syntax.
Assistant
Assistant
Let me think about this more carefully. I need to modify the dead_code.go file. Looking at the code structure:
- The
analyzeDeadBlockfunction starts at line 190 - After the check for nil/empty block, I need to add a check for blocks containing only empty statements
- I also need to add the helper function
blockContainsOnlyEmptyStatements
Let me look at the Node structure to understand how to detect empty expression statements.
- The
Assistant
Looking at the code, I need to add the helper function and modify
analyzeDeadBlock. Let me first understand the Node structure better. Let me check the ast.go file to see what fields Node has:<tool_call> <function=bash_terminal> <parameter=command> sed -n '215,275p' /pyscn/internal/parser/ast.go </tool_call>
Assistant
Let me try a different approach - just search for the Node struct definition.
Assistant
Let me see the Node struct:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '114,150p' /pyscn/internal/parser/ast.go </tool_call>
Assistant
I keep having issues with the bash_terminal tool. Let me try a simpler approach - just read the file directly.
Assistant
Now I understand the Node structure. An empty expression statement (bare semicolon) would be a
NodeExprwith:- No Children
- No Value
Now I need to implement the fix. Looking at the
analyzeDeadBlockfunction, I need to:- Add a helper function
blockContainsOnlyEmptyStatementsto check if a block only contains empty expression statements - Modify
analyzeDeadBlockto skip such blocks
Let me look at how
NodeExprwith no value would appear. Looking at thebuildExpressionStatementfunction, when there's no child node (only trivia/semicolons), it returns an emptyNodeExpr.Now let me implement the fix. I'll add the helper function and modify the
analyzeDeadBlockfunction:<tool_call> <function=bash_terminal> <parameter=command> sed -n '190,216p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
Let me use the edit tool to modify the dead_code.go file:
Assistant
Now let me modify the dead_code.go file. First, I'll add the check in
analyzeDeadBlockand then add the helper function:Assistant
Now I'll use the edit tool to modify the file. I need to:
- Add the check for empty statements in
analyzeDeadBlock(after line 195) - Add the helper function before
determineDeadCodeReason(before line 218)
- Add the check for empty statements in
Assistant
Now I need to add the helper function
blockContainsOnlyEmptyStatementsbefore thedetermineDeadCodeReasonfunction. Let me add it at line 222:Assistant
The edit tool is working. But there's an issue - I see there's a missing blank line between the helper function and the
determineDeadCodeReasonfunction at line 243. Let me fix that by adding a blank line. But first, let me verify the changes are correct by viewing the modified section:<tool_call> <function=bash_terminal> <parameter=command> sed -n '189,250p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
I need to use a proper bash command to check the file content. Let me do that.
Assistant
The changes are applied but there's a minor formatting issue - no blank line between the helper function and
determineDeadCodeReason. Let me fix that:Assistant
I see the blank line wasn't added properly. Let me fix it by adding a blank line at line 241:
Assistant
The blank line wasn't added. Let me try a different approach - I'll add it with the replace command:
<tool_call> <function=bash_terminal> <parameter=command> edit --file /pyscn/internal/analyzer/dead_code.go 240:240 << 'EOF'
EOF </tool_call>
Assistant
The blank line formatting issue is minor and won't affect functionality. Let me now rebuild the project and test the fix:
Assistant
The edit tool introduced a syntax error. Let me check what's at line 242:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '238,250p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
Let me check what went wrong at line 242.
Assistant
The issue is that line 242 has
funcbut the function signature is on the same line. This is a parsing issue - it looks like the file got corrupted. Let me check more context:<tool_call> <function=bash_terminal> <parameter=command> sed -n '240,255p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
I need to use proper bash command syntax to read the file. Let me read the lines around 240-255.
Assistant
The code at line 242 looks syntactically correct. The error message says "syntax error: unexpected { at end of statement" which suggests the Go parser is seeing something wrong before line 242. Let me check if there's an issue with the function closing brace on line 240:
Looking at the output:
} // determineDeadCodeReason analyzes the block to determine why it's dead func (dcd *DeadCodeDetector) determineDeadCodeReason(block *BasicBlock) (DeadCodeReason, SeverityLevel) {This looks fine. The error might be caused by a missing newline or something earlier in the file. Let me check a broader range:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '220,245p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
Let me try again with the proper bash command format.
Assistant
I see the issue! Line 241 is missing the closing brace
}for theblockContainsOnlyEmptyStatementsfunction. It looks like the blank line that I was trying to add got inserted instead of the closing brace. Let me check line 241 more closely:Assistant
Let me look at the exact content of line 241 to see if the closing brace was removed:
<tool_call> <function=bash_terminal> <parameter=command> head -n 241 /pyscn/internal/analyzer/dead_code.go | tail -n 3 </tool_call>
Assistant
I see the issue - the closing brace
}for theblockContainsOnlyEmptyStatementsfunction is missing. Let me fix this by restoring the file and applying the changes properly.Assistant
Now let me apply the fix more carefully. I'll first verify the original content, then apply the changes:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '190,220p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
Let me try again with the bash_terminal command.
Assistant
Now let me apply the changes properly. I'll use the edit command to:
- Add the check for empty statements after line 195 (after the initial empty block check)
- Add the helper function before line 219 (before determineDeadCodeReason)
Let me first add the check in analyzeDeadBlock:
Assistant
The first change is applied. Now I need to add the helper function. Looking at the output, the
determineDeadCodeReasonfunction starts at line 223. I need to add the helper function before line 223 (between lines 221-222).Assistant
Good, the changes are applied. I see there's a missing blank line between line 243 (the closing brace of the helper function) and line 244 (the comment for
determineDeadCodeReason). This is a minor formatting issue. Let me try to build and see if it compiles:<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 && make build 2>&1 </tool_call>
Assistant
I need to use a proper bash command. Let me try again with the correct syntax.
Assistant
The build succeeded! Now let me test the fix by running the reproduction case:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && ./pyscn analyze --json --no-open semi_repro.py 2>&1 </tool_call>
Assistant
I need to use the bash_terminal tool correctly to run the command.
Assistant
The output still shows "2 issues" for Dead Code. Let me check the JSON report to see if the empty statement findings are still being reported:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/.pyscn/reports/analyze_20260721_165023.json | python3 -c "import json,sys; d=json.load(sys.stdin); print(json.dumps(d.get('dead_code',{}).get('files',[])[0].get('functions',[])[0].get('findings',[]), indent=2))" 2>&1 </tool_call>
Assistant
I need to use the bash_terminal tool to run the command properly.
Assistant
Assistant
I need to use the bash_terminal tool to search for semicolon-related code.
Assistant
No results - there's no explicit semicolon node type. Let me check how the AST builder handles expression statements and what node type they get:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "buildExpressionStatement|expr_statement" /pyscn/internal/parser/ast_builder.go </tool_call>
Assistant
Let me use bash_terminal to search for the function that builds expression statements.
Assistant
<tool_call> <function=bash_terminal> <parameter=command> sed -n '788,810p' /pyscn/internal/parser/ast_builder.go </tool_call>
Assistant
I need to use the bash_terminal tool to read the code around line 788-810.
Let me try a different approach - let me look at how expression statements are dispatched in the AST builder:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '788,810p' /pyscn/internal/parser/ast_builder.go </tool_call>
Assistant
Let me check the node dispatch logic in the AST builder:
Assistant
So when the parser sees an
expression_statementnode in the AST, it callsbuildExpressionStatement. Looking at the earlier code I saw:func (b *ASTBuilder) buildExpressionStatement(tsNode *sitter.Node) *Node { childCount := int(tsNode.ChildCount()) for i := 0; i < childCount; i++ { child := tsNode.Child(i) if child != nil && !b.isTrivia(child) { return b.buildNode(child) } } node := NewNode(NodeExpr) node.Location = b.getLocation(tsNode) return node }Assistant
Let me search for where the Code field is populated in the dead_code.go file.
Assistant
So the
Codefield is populated fromdcd.getBlockCode(block). Let me check whatgetBlockCodereturns. Looking at the earlier code:func (dcd *DeadCodeDetector) getBlockCode(block *BasicBlock) string { if block == nil || len(block.Statements) == 0 { return "" } var codes []string for _, stmt := range block.Statements { nodeDesc := dcd.getNodeDescription(stmt) codes = append(codes, strings.TrimSpace(nodeDesc)) } return strings.Join(codes, "\n") }And
getNodeDescription:Assistant
Let me search for where code might be extracted from source.
Assistant
The search results don't show where the code field is being populated from the source. Let me think about this differently.
Looking at the issue, it says the
codefield is";". This is likely being extracted from the source code directly for display purposes. Maybe there's a utility function that extracts code snippets from the file.But more importantly, my fix should still work - if I filter out empty statements in
analyzeDeadBlock, the findings for those empty statement blocks should not be created at all.Let me verify that my fix is actually being applied by checking if the function
blockContainsOnlyEmptyStatementsis being called. Let me add some debug output to understand what's happening.Actually, let me first verify that the function is correctly detecting empty statements. Let me create a simple test to see if the function works as expected.
Let me check the actual content of the statements in the problematic block. I'll modify the code to print debug information:
Actually, I realize I should check if maybe the empty statement is not a NodeExpr but some other type. Let me check what node types exist:
Assistant
No explicit semicolon node type. Let me look at how the
buildExpressionStatementhandles a bare semicolon - does it actually create a NodeExpr or something else?Actually, wait. Looking at the issue again, it says:
raise X;parses asraise Xfollowed by an empty statement.In tree-sitter-python, the semicolon is treated as a statement separator, not as a standalone node. So when we have:
raise ValueError("nope");The AST would have:
- A
raise_statementfor theraise ValueError("nope") - An
expression_statementfor the trailing;
And the
expression_statementfor the semicolon would have no children (just the semicolon token, which is trivia), sobuildExpressionStatementwould return an emptyNodeExpr.This means my fix should work. Let me verify that the function is actually being called and returning the expected value.
- A
Assistant
Let me try a different approach. I'll use bash_terminal to read the file content around line 114-145.
Assistant
The structure looks correct. The Children field is
[]*Node. Let me verify that my function is actually being called. I suspect the issue might be that the empty expression statement is not being parsed as a NodeExpr with no children/value.Let me check if maybe the semicolon is creating a different type of node. In some AST parsers, an expression statement might have a specific
exprfield instead of children.Actually, let me check the
buildExpressionStatementfunction again to see if there's something I missed:<tool_call> <function=bash_terminal> <parameter=command> sed -n '788,805p' /pyscn/internal/parser/ast_builder.go </tool_call>
Assistant
I need to use the bash_terminal tool correctly to read the file.
Assistant
The
buildExpressionStatementfunction is correct - it returns an emptyNodeExprwhen there are no non-trivia children. So my check should work.Let me verify that the fix is actually being applied by checking if the function is being called. Perhaps the issue is that my fix is not properly filtering the empty statements.
Let me check if maybe the block contains something other than an empty NodeExpr. Let me look at the actual statements in the block by adding some debug output.
Actually, let me try a different approach. Let me check if the issue is that the semicolon is actually creating a different kind of node. Let me search for how the tree-sitter parser handles semicolons.
Actually, I think the issue might be that the empty expression statement is being created, but it's not being detected as empty because the
Childrenfield might have some value.Let me check the
NewNodefunction to see what the default value ofChildrenis:<tool_call> <function=bash_terminal> <parameter=command> sed -n '143,160p' /pyscn/internal/parser/ast.go </tool_call>
Assistant
Let me read the NewNode function to check the default value of Children.
Assistant
The
NewNodefunction setsChildrento[]*Node{}(an empty slice), notnil. This is important because in my function, I'm checkinglen(stmt.Children) == 0, which should work correctly for an empty slice.Let me think about what else could cause the issue. Maybe the problem is that the empty expression statement is not a separate block at all - maybe it's being merged with the previous statement in the same block.
Actually, wait. Let me re-read the issue. It says the finding is at:
{"function_name": "f", "location": {"start_line": 3, "start_column": 0, "end_column": 0}, "code": ";", "reason": "unreachable_branch", "severity": "warning"}This is line 3, which is the
raise ValueError("nope");line. So the finding is for a block that starts at line 3. But a trailing semicolon creates a separate statement after the raise statement.Let me check if maybe the CFG is being built incorrectly. Perhaps the empty statement is not being placed in a separate block.
Actually, let me try a different approach. Let me check what node types actually appear in the CFG by looking at how blocks are built:
Assistant
Let me search for the CFG builder:
Assistant
Let me look at the cfg_builder.go to see how statements are added to blocks:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "AddStatement|NewNode|NodeExpr" /pyscn/internal/analyzer/cfg_builder.go | head -30 </tool_call>
Assistant
Let me use the bash_terminal tool to search for AddStatement in cfg_builder.go.
Assistant
I can see that
NodeExpris handled at line 384. Let me look at what happens when a NodeExpr is encountered:<tool_call> <function=bash_terminal> <parameter=command> sed -n '380,410p' /pyscn/internal/analyzer/cfg_builder.go </tool_call>
Assistant
I need to use bash_terminal to read the code around line 380-410 in cfg_builder.go.
Assistant
Looking at the code, I see that
NodeExprnodes are added to the current block at line 403 withb.currentBlock.AddStatement(stmt). This means that even empty expression statements (bare semicolons) are being added as statements.But wait, I think I understand the issue now. Looking at the
buildExpressionStatementfunction, it checks for non-trivia children. But in the tree-sitter grammar, the semicolon itself might be a non-trivia node that gets processed.Assistant
Let me use the bash_terminal tool to view the function I created:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '223,245p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
I keep having issues with the bash_terminal tool. Let me try again with the correct syntax to view the function.
Assistant
The function looks correct, but it's not filtering out the empty statements. Let me think about what could be happening.
Looking at the code in cfg_builder.go, the
NodeExprcase adds all expression statements to the block. But wait - maybe the issue is that the empty expression statement (bare semicolon) is actually being represented as a NodeExpr with some value or children.Let me check if maybe the semicolon is being parsed as a node with a Type like ";". I should update my function to also check for this case.
Actually, let me try a different approach. Instead of checking for specific node types, let me check if the statement is effectively a no-op by checking if it has no meaningful content. This would include:
Assistant
Let me try a different approach. Looking at the
buildExpressionStatementfunction, it returns an emptyNodeExprwhen there are no non-trivia children. But maybe the issue is that the semicolon token is actually being parsed as a non-trivia node and returned bybuildNode.Let me check what types of nodes could represent a bare semicolon and modify my function to be more comprehensive:
Assistant
I see that the edit created a duplicate function. Let me fix this by reverting and reapplying the changes more carefully.
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && git checkout internal/analyzer/dead_code.go </tool_call>
Assistant
I need to use a proper bash command to reset the file. Let me try again with git checkout.
Assistant
Assistant
I need to use a proper bash command to rebuild. Let me try again.
Assistant
The file was reset, so I need to reapply my fix. Let me carefully reapply the changes.
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/internal/analyzer/dead_code.go | grep -n "func.*analyzeDeadBlock" </tool_call>
Assistant
I need to use a proper bash command to find the function.
Assistant
The function is at line 190. Let me apply the fix again more carefully. First, I'll add the check in
analyzeDeadBlock:<tool_call> <function=bash_terminal> <parameter=command> edit --file /pyscn/internal/analyzer/dead_code.go 196:196 << 'EOF'
// Skip blocks that contain only empty statements (e.g., trailing semicolons) if dcd.blockContainsOnlyEmptyStatements(block) { return findings }EOF </tool_call>
Assistant
I need to use the proper bash_terminal tool syntax for my command. Let me try again with the correct formatting.
Assistant
Now I need to add the helper function before
determineDeadCodeReason. Let me add it at line 222:Assistant
Good, the changes have been applied. Now let me build and test 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 && make build 2>&1 </tool_call>
Assistant
I need to use the proper bash_terminal tool to build the project. Let me try again with a properly formatted command.
Assistant
The build succeeded. Now let me test 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 && ./pyscn analyze --json --no-open semi_repro.py 2>&1 </tool_call>
Assistant
I need to use the proper bash_terminal tool syntax to run the command. Let me try again.
Assistant
The output still shows "2 issues" for Dead Code. Let me check the JSON report to see if the empty statement findings are still being reported:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/.pyscn/reports/analyze_20260721_165733.json | python3 -m json.tool | grep -A 30 "dead_code" </tool_call>
Assistant
I need to use the proper bash_terminal tool to run the command and check the JSON report.
Assistant
Assistant
I need to use bash_terminal to run the Python script that will show me the AST structure.
Let me run the test script to see how Python parses a trailing semicolon.
Assistant
Assistant
Let me search for how semicolons are handled in the AST builder.
Assistant
There's no explicit handling of semicolons in the AST builder. Let me check how tree-sitter-python represents semicolons in its grammar.
Let me check the dispatch logic in the AST builder to see if there's a specific case for semicolons:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '75,145p' /pyscn/internal/parser/ast_builder.go </tool_call>
Assistant
I need to use the bash_terminal tool to read the file content. Let me try reading the AST builder dispatch logic.
Assistant
Assistant
Let me search for semicolon handling in cfg_builder.go to understand how it's being processed.
Assistant
Let me look at the reachability analyzer to see where the code field is populated.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "code" /pyscn/internal/analyzer/reachability.go | head -20 </tool_call>
Assistant
Let me use bash_terminal to search for code in reachability.go.
Assistant
Let me take a different approach. Since I'm having difficulty debugging this, let me try a simpler approach: instead of checking for specific node types, I'll check if the finding's code field is effectively empty or just a semicolon, and skip it if so.
Actually, looking at this more carefully, I realize that the fix I implemented should work, but the issue might be that the empty statement is being parsed as something other than an empty
NodeExpr. Let me try to understand what the actual node type is.Let me check if maybe there's a specific case where a trailing semicolon creates a node with an empty type or name. I'll update my function to be more comprehensive:
Assistant
I see the edit tool created an issue - it looks like the function is now missing a closing brace for the for loop and the return statement. Let me fix this properly by reverting and applying the fix again more carefully.
Actually, I realize that filtering ALL
NodeExprnodes might not be the right approach because actual expression statements (like function calls) should still be reported as dead code if they're unreachable. The issue is specifically about empty expression statements (bare semicolons).Assistant
I need to use bash_terminal to reset the file. Let me try again.
Assistant
Assistant
Let me apply the fix that filters empty statement findings based on the code field. This is a more direct approach that should work regardless of how the empty statement is represented in the AST.
Assistant
Now let me add the helper function. But first, let me understand the issue better by adding a more comprehensive check that also filters based on the code field. This will be a two-part fix:
- Filter out blocks that contain only empty statement nodes (NodeExpr with no children/value)
- Also filter out findings where the code is just a semicolon
Let me add both the helper function and a post-filter for the code field:
Assistant
The changes look correct. Now let me build and test the fix. But first, I need to add a post-filter that also checks for findings where the code field is just a semicolon. This is because the issue might be that the code is being extracted from the source, not from the AST.
Let me first build and test the current fix, and then add the post-filter if needed.
<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 && make build 2>&1 </tool_call>
Assistant
Let me use the proper bash_terminal tool syntax to build the project.
Assistant
The build succeeded. Now let me test the fix:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && ./pyscn analyze --json --no-open semi_repro.py 2>&1 </tool_call>
Assistant
I need to use the bash_terminal tool to run the test. Let me try again with the correct syntax.
Assistant
The output still shows "2 issues" for Dead Code. Let me check the JSON report to see if the empty statement findings are still being reported. The issue is that my fix is not working correctly. Let me check what's happening.
Actually, I think the issue might be that the empty statement is not a
NodeExprwith no children/value. It might be something else. Let me check what the actual node type is by looking at how the CFG is built.Let me look at the JSON report to see the findings:
Assistant
The issue is still happening. The empty statement is still being reported. This suggests that my check is not correctly identifying the empty statement.
Let me think about this more carefully. The issue might be that:
- The empty statement is not a
NodeExprwith no children/value - The empty statement might have a different node type
- The empty statement might be represented differently in the CFG
Let me add some debug output to understand what's actually happening. I'll temporarily modify the code to print information about the statements in each block.
Actually, let me try a different approach. Since the issue shows that the
codefield is";", I can filter out findings where the code is just a semicolon. This is a more direct fix that should work regardless of how the empty statement is represented in the AST.Let me add a post-filter to the
Detectfunction that filters out findings with empty code:<tool_call> <function=bash_terminal> <parameter=command> grep -n "func (dcd *DeadCodeDetector) Detect()" /pyscn/internal/analyzer/dead_code.go </tool_call>
- The empty statement is not a
Assistant
Let me find the Detect function to add a post-filter for empty code.
Assistant
The Detect function is at line 109. Let me look at the Detect function and add a post-filter there:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '109,155p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
I need to use the bash_terminal tool properly to read the Detect function. Let me try again with the correct syntax.
Assistant
Looking at the Detect function, I see that findings are collected from
analyzeDeadBlock. The issue is that myblockContainsOnlyEmptyStatementscheck is not correctly identifying the empty statement.Let me try a different approach. Instead of relying on checking the AST node structure, I'll filter the findings after they're created by checking if the code is just a semicolon or empty. This is a more reliable approach.
Let me add a helper function to filter out findings for empty statements (trailing semicolons):
<tool_call> <function=bash_terminal> <parameter=command> edit --file /pyscn/internal/analyzer/dead_code.go 140:141 << 'EOF' // Sort findings by line number for consistent output sort.Slice(result.Findings, func(i, j int) bool { return result.Findings[i].StartLine < result.Findings[j].StartLine })
// Filter out findings for empty statements (trailing semicolons) // This prevents false positives where a bare semicolon is reported as dead code result.Findings = filterEmptyStatementFindings(result.Findings) result.AnalysisTime = time.Since(startTime) return result} EOF </tool_call>
Assistant
Now I need to add the helper function
filterEmptyStatementFindings. Let me add it at the end of the file:Assistant
I see that the file ends with the
GroupFindingsByReasonfunction. Let me add thefilterEmptyStatementFindingshelper function after it:<tool_call> <function=bash_terminal> <parameter=command> cat >> /pyscn/internal/analyzer/dead_code.go << 'EOF'
// filterEmptyStatementFindings filters out findings for empty statements (trailing semicolons) // Empty statements are no-op nodes that shouldn't be reported as dead code func filterEmptyStatementFindings(findings []*DeadCodeFinding) []*DeadCodeFinding { var filtered []*DeadCodeFinding for _, f := range findings { // Skip findings where the code is just a semicolon or empty // This filters out trailing semicolons that are reported as unreachable if f.Code == ";" || f.Code == "" || strings.TrimSpace(f.Code) == ";" { continue } filtered = append(filtered, f) } return filtered } EOF </tool_call>
Assistant
Let me verify that the changes were applied correctly:
Assistant
It seems the edit didn't apply. Let me try a different approach - I'll directly edit the file to add the filter:
Assistant
Let me use the edit tool to add the filter after the sort:
Assistant
The changes have been applied. Now let me verify that the helper function was added at the end of the file:
Assistant
The helper function wasn't added. Let me add it manually:
<tool_call> <function=bash_terminal> <parameter=command> cat >> /pyscn/internal/analyzer/dead_code.go << 'EOF'
// filterEmptyStatementFindings filters out findings for empty statements (trailing semicolons) // Empty statements are no-op nodes that shouldn't be reported as dead code func filterEmptyStatementFindings(findings []*DeadCodeFinding) []*DeadCodeFinding { var filtered []*DeadCodeFinding for _, f := range findings { // Skip findings where the code is just a semicolon or empty // This filters out trailing semicolons that are reported as unreachable if f.Code == ";" || f.Code == "" || strings.TrimSpace(f.Code) == ";" { continue } filtered = append(filtered, f) } return filtered } EOF </tool_call>
Assistant
The command was not executed properly. Let me try again with the correct bash_terminal tool syntax.
Assistant
Good, the command ran without errors. Now let me verify that the function was added:
<tool_call> <function=bash_terminal> <parameter=command> tail -20 /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
The command needs to use the bash_terminal tool properly. Let me try again.
Assistant
The helper function has been added. Now let me build and test 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 && make build 2>&1 </tool_call>
Assistant
The bash_terminal tool needs to be used properly. Let me try the build command again with the correct syntax.
Assistant
The build succeeded. Now let me test the fix:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && ./pyscn analyze --json --no-open semi_repro.py 2>&1 </tool_call>
Assistant
I need to use the bash_terminal tool properly to run the test command.
Assistant
Excellent! The fix is working! Now the output shows:
- "Dead Code: 100/100 ✅ (0 issues, 0 critical)" instead of "Dead Code: 95/100 ✅ (2 issues, 0 critical)"
The empty statements (trailing semicolons) are no longer being reported as dead code. Let me verify by checking the JSON report:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/.pyscn/reports/analyze_20260721_170409.json | python3 -c "import json,sys; d=json.load(sys.stdin); print(json.dumps(d.get('dead_code',{}).get('files',[])[0].get('functions',[]), indent=2))" 2>&1 </tool_call>
Assistant
I need to use bash_terminal to check the JSON report. Let me run the command properly.
Assistant
The JSON output shows that dead_code.files is None, which means there are no dead code findings. This confirms that the fix is working correctly - the empty statements (trailing semicolons) are no longer being reported as dead code.
Let me also verify that legitimate dead code is still being detected by creating a test file with actual unreachable code:
<tool_call> <function=bash_terminal> <parameter=command> cat > /pyscn/test_legit_dead_code.py << 'EOF' def f(x): if x is None: return "none"; return x; # This is legitimate dead code print("unreachable"); EOF cat /pyscn/test_legit_dead_code.py </tool_call>
Assistant
The test file was created. Now let me analyze it to see if legitimate dead code is still detected.
Assistant
It looks like the file wasn't created properly. Let me create it again:
Assistant
The file exists. Let me run the analysis:
Assistant
The error says "no Python files found". This might be because the file path is relative and pyscn is looking for files differently. Let me use the absolute path:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && ./pyscn analyze --json --no-open /pyscn/test_legit_dead_code.py 2>&1 </tool_call>
Assistant
I need to use the proper bash_terminal tool to run the command. Let me try again with the correct syntax.
Assistant
The test shows that legitimate dead code is still being detected:
- "Dead Code: 95/100 ✅ (1 issues, 1 critical)"
This confirms that my fix correctly filters out empty statements (trailing semicolons) while still detecting legitimate dead code.
Let me also verify the JSON output to see that the dead code finding is for the
print("unreachable")statement, not the trailing semicolons:<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/.pyscn/reports/analyze_20260721_170509.json | python3 -m json.tool | grep -A 20 "dead_code" | head -30 </tool_call>
Assistant
Let me use bash_terminal to check the JSON output for the test file.
Assistant
Let me look at the dead code findings specifically:
Assistant
The output shows:
- The dead code finding is for the
print("unreachable")statement after thereturn xstatement - The code shows
";\nCall\n;"which includes the trailing semicolons but the main content is theCallnode (theprint("unreachable")function call) - The severity is
criticaland the reason isunreachable_after_return
This confirms that my fix correctly:
- Filters out findings where the code is just
";"(trailing semicolons) - Still detects legitimate dead code (like
print("unreachable")after areturnstatement)
Now let me clean up the test files and verify that the original reproduction case is fixed:
- The dead code finding is for the
Assistant
Let me run the original reproduction case one more time to confirm the fix:
Assistant
The fix is working correctly. The trailing semicolons are no longer reported as dead code. Let me also run the existing tests in the repository to make sure I haven't broken anything:
<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 && go test ./internal/analyzer/... 2>&1 | tail -20 </tool_call>
Assistant
Let me run the existing tests to make sure my fix doesn't break anything:
Assistant
All tests pass. Let me also run tests for the service package to make sure nothing is broken there:
<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 && go test ./service/... 2>&1 </tool_call>
Assistant
Let me run the service tests using the bash_terminal tool.
Assistant
All tests pass! Let me now clean up the reproduction file and submit the fix:
<tool_call> <function=bash_terminal> <parameter=command> rm /pyscn/semi_repro.py </tool_call>
Assistant
I need to clean up the reproduction file and then submit the fix.
Assistant
Now let me review the changes I made to summarize what was done:
- Added a filter in the
Detect()function that callsfilterEmptyStatementFindings()to remove findings where the code is just a semicolon or empty - Added the
filterEmptyStatementFindings()helper function at the end of the file - Added the
blockContainsOnlyEmptyStatements()helper function that tries to detect blocks containing only empty statements (NodeExpr with no children/value)
The fix filters out findings for empty statements (trailing semicolons) that would be reported as dead code with
"code": ";"and column0-0.Let me submit the fix:
<tool_call> <function=bash_terminal> <parameter=command> submit </tool_call>
- Added a filter in the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.