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 exploring the repository structure to understand how it's organized and find the relevant code for the dead-code detector.
Assistant
Let me explore more of the structure to understand the codebase organization.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /pyscn </tool_call>
Assistant
Let me run a simple ls command to list the directory contents.
Assistant
This is a Go project with Python tooling. Let me find the dead-code detector and understand its implementation.
<tool_call> <function=bash_terminal> <parameter=command> find /pyscn -type f -name "*.go" | xargs grep -l "dead.code|deadcode|unreachable" 2>/dev/null | head -20 </tool_call>
Assistant
Let me search for dead code related files properly.
Assistant
Let me look at the dead code analyzer implementation:
Assistant
Now let me look at the reachability analyzer to understand how unreachable blocks are identified:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/internal/analyzer/reachability.go </tool_call>
Assistant
Let me continue with the bash command to view the reachability analyzer.
Assistant
Now I need to understand how empty blocks are determined. Let me look at the basic block structure:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/internal/analyzer/cfg.go </tool_call>
Assistant
Let me look at the cfg.go file to understand the BasicBlock structure and the IsEmpty method.
Assistant
Now let me understand the parser to see how empty statements (like a bare
;) are represented. The issue is that when there's a trailing semicolon afterraiseorreturn, the parser creates a separate node for the;that gets its own block. Let me look at the parser code:<tool_call> <function=bash_terminal> <parameter=command> find /pyscn -type f -name "*.go" | xargs grep -l "NodeSemi|semi|semicolon" 2>/dev/null | head -10 </tool_call>
Assistant
Let me search for semicolon handling in the parser.
Assistant
The output only shows one file. Let me check that file and also look at the parser package to understand how nodes are defined:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/internal/analyzer/raw_metrics_test.go </tool_call>
Assistant
Let me run the command properly to check that file.
Assistant
This file mentions semicolons in a test. Now let me look at the parser package to understand how AST nodes are defined:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /pyscn/internal/parser/ </tool_call>
Assistant
Let me properly list the parser directory contents.
Assistant
Let me look at ast.go to understand the Node types and how statements are defined.
Assistant
Now I understand the AST structure. Let me first create the reproduction file and run the analyzer to confirm the issue:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && cat > /tmp/semi_repro.py << 'EOF' def f(x): if x is None: raise ValueError("nope"); return x
def g(y): return y; EOF
Assistant
Let me create the test file to reproduce the issue.
Assistant
Now let me build and run the analyzer to confirm the issue:
Assistant
Let me set up the Go module cache and try again.
Assistant
Let me set more environment variables for Go build.
Assistant
The build succeeded. Now let me run the analyzer on the test file to reproduce the issue:
Assistant
Let me check the JSON report to see the findings:
Assistant
Let me see more of the JSON output to see all the findings:
Assistant
Let me also check the second function to see the second finding.
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/.pyscn/reports/analyze_20260721_164314.json | python3 -c "import sys,json; d=json.load(sys.stdin); print(json.dumps(d['dead_code']['files'][0]['functions'][1]['findings'], indent=2))" </tool_call>
Assistant
Let me check the second function findings.
Assistant
I've confirmed the issue! The dead code detector is reporting the semicolon as unreachable code with:
code: ";"start_column: 0, end_column: 0(the impossible column range mentioned in the issue)reason: "unreachable_branch"severity: "warning"
Now I need to understand where this is coming from. The fix suggested in the issue is to skip empty statements (bare
;orpass) when collecting unreachable-branch findings.Looking at the code:
- In
dead_code.go, theanalyzeDeadBlockmethod creates findings for unreachable blocks - In
reachability.go,GetUnreachableBlocksWithStatementsreturns blocks that are not "empty"
The
IsEmpty()method incfg.gochecks iflen(bb.Statements) == 0. But the issue is that a block containing just a semicolon has one statement (the semicolon), so it's not considered empty!Let me check how the AST parser creates nodes for semicolons. Let me look at the AST builder:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/internal/parser/ast_builder.go | head -200 </tool_call>
Assistant
Let me run the command properly to view the ast_builder.go file.
Assistant
So there's no specific handling for semicolons in the AST builder. Let me check what the parser actually returns for a bare semicolon:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/test_parser.py << 'EOF' import ast
code = """ def f(x): if x is None: raise ValueError("nope"); return x """
tree = ast.parse(code) print(ast.dump(tree, indent=2)) EOF python3 /tmp/test_parser.py </tool_call>
Assistant
Let me try again with the proper bash command format.
Assistant
Interesting! The standard Python AST parser doesn't include the semicolon in the AST at all - it just treats the
;as a statement separator. But this tool is using tree-sitter (Go-based), and it seems to be creating a separate node for the semicolon.Let me check how this project parses Python code - it might be using tree-sitter-python:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "tree-sitter|TreeSitter" /pyscn/internal/parser/parser.go </tool_call>
Assistant
Let me search for tree-sitter in the parser.go file.
Assistant
Let me look at the AST builder to understand how semicolons are processed:
Assistant
Let me check the buildReturnStatement and buildRaiseStatement methods to see how they handle trailing semicolons:
Assistant
Now let me check how blocks are built. The issue is that when a return or raise statement is followed by a semicolon, the parser might create a separate statement for that semicolon:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1676,1750p' /pyscn/internal/parser/ast_builder.go </tool_call>
Assistant
Let me try again with the sed command to view the buildBlock function.
Assistant
Now let me check the
isTriviamethod to understand what the parser considers as trivia (whitespace, comments, semicolons, etc.):<tool_call> <function=bash_terminal> <parameter=command> grep -n "isTrivia" /pyscn/internal/parser/ast_builder.go </tool_call>
Assistant
Let me search for the isTrivia method definition in the ast_builder.go file.
Assistant
Let me look at the isTrivia function definition to see what it considers as trivia:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '2073,2100p' /pyscn/internal/parser/ast_builder.go </tool_call>
Assistant
Let me continue to view the isTrivia function to understand what it considers as trivia.
Assistant
Now I understand the issue. The
isTriviafunction doesn't consider semicolons as trivia, so they're parsed as separate statements. The fix should be to filter out semicolon-only statements when generating dead-code findings.Let me first write a simple Go program to understand what tree-sitter produces for a semicolon:
Assistant
Let me fix the Go program:
Assistant
I see the issue! The tree-sitter parser creates a
;node as a sibling of theraise_statementinside theblock. This;node becomes a separate statement that gets added to the block.Now I understand the flow:
- Tree-sitter creates a
;node that's a sibling toraise_statement - When building the block, the AST builder processes all children of the block, including the semicolon
- The semicolon becomes a separate statement in the block
- When the return statement is analyzed, the semicolon is in a block after the return
- The dead code detector flags the semicolon as unreachable
The fix should be to filter out these semicolon-only blocks when generating dead code findings. Looking at the code in
dead_code.go, theanalyzeDeadBlockfunction should check if the block contains only semicolons.Let me look at how blocks are converted to dead code findings again:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '190,240p' /pyscn/internal/analyzer/dead_code.go </tool_call>
- Tree-sitter creates a
Assistant
Let me continue viewing the dead_code.go file to find the analyzeDeadBlock function.
Assistant
Now I understand the issue. Tree-sitter creates a
;node as a separate statement afterraiseorreturnwhen followed by a semicolon. This becomes an "empty statement" that is flagged as unreachable dead code.Let me check what node type the semicolon is represented as in the internal AST:
Assistant
Let me write the check_ast.go file inside the pyscn project directory to use internal packages.
<tool_call> <function=bash_terminal> <parameter=command> cat > /pyscn/check_ast.go << 'EOF' package main
import ( "context" "fmt"
"github.com/ludo-technologies/pyscn/internal/parser")
func main() { p := parser.New() code := []byte(
def f(x): if x is None: raise ValueError("nope"); return x)result, err := p.Parse(context.Background(), code) if err != nil { panic(err) } var walk func(node *parser.Node, depth int) walk = func(node *parser.Node, depth int) { prefix := "" for i := 0; i < depth; i++ { prefix += " " } children := node.GetChildren() fmt.Printf("%sType: %s, Name: %q, Children: %v, Lines: %d-%d\n", prefix, node.Type, node.Name, children, node.Location.StartLine, node.Location.EndLine) for _, child := range children { walk(child, depth+1) } } walk(result.AST, 0)} EOF
cd /pyscn && export GOPATH=/tmp/go && export GOMODCACHE=/tmp/go/pkg/mod && export GOCACHE=/tmp/go/cache && go run check_ast.go 2>&1 </tool_call>
Assistant
Let me run the Go program to check how semicolons are represented in the internal AST.
Assistant
It seems the file wasn't created. Let me check and create it properly:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /pyscn/check_ast.go 2>&1 || echo "File doesn't exist" </tool_call>
Assistant
Let me verify the file exists and run it.
Assistant
The heredoc approach didn't work. Let me use the create tool to make the file:
Assistant
Good, let me now run this to understand how the AST handles semicolons.
Assistant
Now I see the issue! The
;is being parsed as a separateNodeTypewith value" ;"(a semicolon character). This is being added to theIfnode's body as a child, and when this is converted to a CFG block, it becomes an "unreachable" statement after theraise.The fix should be to filter out these semicolon-only statements when creating dead code findings. Looking at the code:
- In
dead_code.go, theanalyzeDeadBlockfunction should check if the block contains only semicolons - In
getNodesDescription, there's already handling for various node types, but not for semicolons
Let me now look at the code more carefully to understand how to fix this. The fix should be in the
analyzeDeadBlockfunction to skip blocks that contain only semicolons (empty statements).Looking at the Node type, a bare semicolon is represented as a node with
Type: ";". This is what we need to filter out.Let me first look at the
getBlockCodefunction to understand how the code is extracted:<tool_call> <function=bash_terminal> <parameter=command> sed -n '385,425p' /pyscn/internal/analyzer/dead_code.go </tool_call>
- In
Assistant
Let me continue to view the getBlockCode function in dead_code.go to understand how the code is extracted.
Assistant
Now I understand the issue. The semicolon
;is parsed as a node with type";", and when araiseorreturnstatement is followed by a semicolon, it creates a separate block containing only the semicolon, which is then flagged as unreachable dead code.The fix should be to filter out these "empty statements" (bare
;) when collecting unreachable-branch findings. Let me implement this fix by modifying theanalyzeDeadBlockfunction indead_code.go:Assistant
Let me look at the analyzeDeadBlock function in its entirety to understand how to modify it.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '189,220p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
Let me view the analyzeDeadBlock function in dead_code.go to understand how to modify it.
Assistant
Now I understand the issue. The fix should be in the
analyzeDeadBlockfunction to filter out blocks that contain only semicolons (empty statements). Let me check if there's a way to identify these semicolon nodes:<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && go run check_ast.go 2>&1 | grep -E "^.*Type: ;" </tool_call>
Assistant
Let me search for the semicolon node type in the AST output.
Assistant
Now I understand the issue. The semicolon is parsed as a node with
Type: ";". I need to modify theanalyzeDeadBlockfunction to filter out blocks that contain only semicolons.Let me implement the fix:
Assistant
Now let me update the dead_code.go file with the fix. I'll use the edit command to replace the analyzeDeadBlock function:
Assistant
Let me now update the dead_code.go file with the fix:
Assistant
Now let me replace the analyzeDeadBlock function with the fixed version using the edit command:
Assistant
Let me verify the changes were applied correctly:
Assistant
Good, the changes are in place but there's a missing blank line between the two functions. Let me fix that:
Assistant
Let me verify the file looks correct now:
Assistant
Let me fix the formatting issue properly:
Assistant
Let me fix this formatting issue properly:
Assistant
Let me just view the current state and then fix it properly:
Assistant
Let me fix the formatting by editing the file to clean up the extra newlines:
Assistant
Let me check if the fix worked:
Assistant
Let me try using gofmt to fix the formatting:
Assistant
Let me verify the formatting is fixed now:
Assistant
Let me clean up the extra blank line:
Assistant
Let me take a more direct approach - let me check if go build works and the code compiles first, then focus on testing.
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && export GOPATH=/tmp/go && export GOMODCACHE=/tmp/go/pkg/mod && export GOCACHE=/tmp/go/cache && go build -o /tmp/pyscn ./cmd/pyscn 2>&1 </tool_call>
Assistant
Let me try again with the proper bash command.
Assistant
The code compiles successfully. Now let me test the fix by running the analyzer on the test file:
<tool_call> <function=bash_terminal> <parameter=command> /tmp/pyscn analyze --json --no-open /tmp/semi_repro.py 2>&1 </tool_call>
Assistant
Let me run the command to test the fix.
Assistant
The fix worked! Notice the dead code score is now 100/100 with "0 issues" instead of 95/100 with "2 issues". Let me verify by checking the JSON report:
<tool_call> <function=bash_terminal> <parameter=command> cat /pyscn/.pyscn/reports/analyze_20260721_165039.json | python3 -c "import sys,json; d=json.load(sys.stdin); print('Dead code:', json.dumps(d.get('dead_code', {}), indent=2))" </tool_call>
Assistant
Let me run the command to verify the JSON output.
Assistant
The fix is working. The dead code section shows "total_findings: 0" and all the findings are now empty/null. The semicolon-only blocks are no longer being reported as dead code.
Now let me test some edge cases to make sure the fix is complete and doesn't break anything:
- Test with actual dead code (should still be detected)
- Test with semicolons in other contexts
- Test with multiple semicolons
Let me create a more comprehensive test file:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/semi_test_edge_cases.py << 'EOF' def test_trailing_semi_after_return(): return 1;
def test_trailing_semi_after_raise(): if True: raise ValueError("error");
def test_trailing_semi_after_break(): while True: break;
def test_trailing_semi_after_continue(): while False: continue;
def test_normal_dead_code_should_still_be_detected(): return 1 x = 2 # This should still be detected as dead code
def test_semicolon_between_statements(): x = 1; y = 2; # Semicolons as statement separators should be fine return x;
def test_multiple_trailing_semicolons(): return 1;; # Multiple trailing semicolons EOF
Assistant
Let me create the test file properly.
Assistant
Now let me run the analyzer on this edge case file:
<tool_call> <function=bash_terminal> <parameter=command> /tmp/pyscn analyze --json --no-open /tmp/semi_test_edge_cases.py 2>&1 </tool_call>
Assistant
Let me run the command to test the edge cases.
Assistant
There's a syntax error in the test file. Let me check what's wrong with it and fix the test cases:
<tool_call> <function=bash_terminal> <parameter=command> python3 -m py_compile /tmp/semi_test_edge_cases.py 2>&1 </tool_call>
Assistant
Let me run the syntax check on the test file.
Assistant
Oops, I see that Python doesn't allow multiple consecutive semicolons in a row. Let me fix the test file and test again:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/semi_test_edge_cases.py << 'EOF' def test_trailing_semi_after_return(): return 1;
def test_trailing_semi_after_raise(): if True: raise ValueError("error");
def test_trailing_semi_after_break(): while True: break;
def test_trailing_semi_after_continue(): while False: continue;
def test_normal_dead_code_should_still_be_detected(): return 1 x = 2 # This should still be detected as dead code
def test_semicolon_between_statements(): x = 1; y = 2; # Semicolons as statement separators should be fine return x;
def test_multiple_statements_with_trailing_semi(): return 1; y = 2; # This should be dead code EOF
Assistant
Let me verify the test file was created correctly:
<tool_call> <function=bash_terminal> <parameter=command> python3 -m py_compile /tmp/semi_test_edge_cases.py 2>&1 && echo "Syntax OK" </tool_call>
Assistant
I need to verify the test file is valid Python and then run the analyzer on it. Let me run both commands.
Assistant
Let me check the file content and rewrite it properly:
Assistant
The heredoc command didn't overwrite the file. Let me remove and recreate it:
<tool_call> <function=bash_terminal> <parameter=command> rm /tmp/semi_test_edge_cases.py && cat > /tmp/semi_test_edge_cases.py << 'ENDOFFILE' def test_trailing_semi_after_return(): return 1;
def test_trailing_semi_after_raise(): if True: raise ValueError("error");
def test_trailing_semi_after_break(): while True: break;
def test_trailing_semi_after_continue(): while False: continue;
def test_normal_dead_code_should_still_be_detected(): return 1 x = 2 # This should still be detected as dead code
def test_semicolon_between_statements(): x = 1; y = 2; # Semicolons as statement separators should be fine return x;
def test_statement_after_semi(): return 1; y = 2; # This should be dead code ENDOFFILE python3 -m py_compile /tmp/semi_test_edge_cases.py && echo "Syntax OK" </tool_call>
Assistant
The command didn't execute - it seems the shell prompt is showing differently. Let me check the file and run the syntax check in separate commands.
Assistant
The file wasn't overwritten. Let me force remove and recreate it:
<tool_call> <function=bash_terminal> <parameter=command> rm /tmp/semi_test_edge_cases.py 2>/dev/null; cat > /tmp/semi_test_edge_cases.py << 'ENDOFFILE' def test_trailing_semi_after_return(): return 1;
def test_trailing_semi_after_raise(): if True: raise ValueError("error");
def test_trailing_semi_after_break(): while True: break;
def test_trailing_semi_after_continue(): while False: continue;
def test_normal_dead_code_should_still_be_detected(): return 1 x = 2 # This should still be detected as dead code
def test_semicolon_between_statements(): x = 1; y = 2; # Semicolons as statement separators should be fine return x;
def test_statement_after_semi(): return 1; y = 2; # This should be dead code ENDOFFILE </tool_call>
Assistant
It seems the heredoc approach with cat is not working properly in this shell. Let me try a different approach using echo or printf to create the file.
Assistant
Let me verify the test file is correct and run the syntax check:
<tool_call> <function=bash_terminal> <parameter=command> python3 -m py_compile /tmp/semi_test_edge_cases.py && echo "Syntax OK" </tool_call>
Assistant
The command didn't execute. Let me try running the command separately.
Assistant
Good, the syntax check passed. Now let me run the analyzer on this test file to verify:
- Trailing semicolons after return/raise/break/continue are NOT reported
- Actual dead code (x = 2 after return 1) IS still reported
- Statements after a semicolon after a return ARE reported as dead code
Assistant
Let me verify that the correct dead code findings are being reported:
Assistant
The fix is working correctly:
-
Trailing semicolons after return/raise/break/continue are NOT reported - Functions
test_trailing_semi_after_return,test_trailing_semi_after_raise,test_trailing_semi_after_break,test_trailing_semi_after_continue, andtest_semicolon_between_statementshave no findings. -
Actual dead code IS still reported:
test_normal_dead_code_should_still_be_detected: Thex = 2assignment afterreturn 1is correctly reported as "unreachable_after_return" with severity "critical"test_statement_after_semi: They = 2assignment afterreturn 1;is correctly reported (the semicolon is filtered out, but the assignment is still detected as dead code)
The fix is working as expected! Now let me run the existing tests to make sure we didn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && export GOPATH=/tmp/go && export GOMODCACHE=/tmp/go/pkg/mod && export GOCACHE=/tmp/go/cache && go test ./internal/analyzer/... -v 2>&1 | head -100 </tool_call>
-
Assistant
Let me run the tests in the analyzer package to verify the fix doesn't break existing tests.
Assistant
Let me continue to see if all tests pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && export GOPATH=/tmp/go && export GOMODCACHE=/tmp/go/pkg/mod && export GOCACHE=/tmp/go/cache && go test ./internal/analyzer/... -v 2>&1 | tail -100 </tool_call>
Assistant
Let me continue to check the test results.
Assistant
All tests pass. Let me also run the service tests to make sure the dead code service tests pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && export GOPATH=/tmp/go && export GOMODCACHE=/tmp/go/pkg/mod && export GOCACHE=/tmp/go/cache && go test ./service/... -v 2>&1 | head -100 </tool_call>
Assistant
Let me run the service tests to make sure the dead code service tests pass.
Assistant
Let me check if all tests pass in the service package.
Assistant
All tests pass! Let me also run the full test suite to make sure the fix doesn't break anything else:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && export GOPATH=/tmp/go && export GOMODCACHE=/tmp/go/pkg/mod && export GOCACHE=/tmp/go/cache && go test ./... 2>&1 | tail -30 </tool_call>
Assistant
Let me run the full test suite to make sure the fix doesn't break anything else.
Assistant
All tests pass! The fix is complete and working. Let me also clean up the temporary files I created:
<tool_call> <function=bash_terminal> <parameter=command> rm /pyscn/check_ast.go 2>/dev/null; rm /tmp/fix.txt /tmp/semi_repro.py /tmp/semi_test_edge_cases.py /tmp/pyscn 2>/dev/null; rm /pyscn/internal/analyzer/dead_code_patch.txt 2>/dev/null; echo "Cleanup done" </tool_call>
Assistant
Let me run the cleanup command.
Assistant
Let me verify the fix one more time by looking at the modified dead_code.go file:
Assistant
The fix is complete. Let me summarize what was done:
Summary of Changes
Issue
The dead-code detector was incorrectly reporting trailing semicolons (e.g.,
raise ValueError("nope");) as unreachable dead code with:code: ";"start_column: 0, end_column: 0(an impossible column range)reason: "unreachable_branch"severity: "warning"
Root Cause
The tree-sitter parser (which pyscn uses for Python parsing) creates a separate
;node as a child of the block when a statement is followed by a semicolon. This semicolon node gets its own CFG block, which is flagged as unreachable dead code after the / statement.Assistant
Let me run the git diff command to see the changes I've made.
Assistant
There are some extra blank lines that were added by the
gofmtcommand. These are cosmetic but should be cleaned up. Let me fix this by removing the extra blank lines:<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && sed -i '/^/ { N; /^\n$/d; }' internal/analyzer/dead_code.go && gofmt -w internal/analyzer/dead_code.go </tool_call>
Assistant
Let me run the sed command to clean up the extra blank lines.
Assistant
The file was reformatted. Let me verify the changes look clean now:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && git diff internal/analyzer/dead_code.go | head -60 </tool_call>
Assistant
Let me see the git diff to verify the changes look clean.
Assistant
I see there are some extra blank lines that were inadvertently added during my editing. Let me restore the original file and apply only the necessary fix cleanly.
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && git checkout -- internal/analyzer/dead_code.go </tool_call>
Assistant
Let me restore the original file and apply the fix cleanly without the extra blank lines.
Assistant
Now let me view the original file and create a clean patch:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '189,220p' /pyscn/internal/analyzer/dead_code.go </tool_call>
Assistant
Let me view the original file to understand its structure and create a clean fix:
Assistant
Good. Now let me create a clean edit that adds the semicolon filtering logic:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/fix_code.txt << 'EOF' // analyzeDeadBlock analyzes a dead block and creates appropriate findings func (dcd *DeadCodeDetector) analyzeDeadBlock(block *BasicBlock) []*DeadCodeFinding { var findings []*DeadCodeFinding
if block == nil || len(block.Statements) == 0 { return findings } // Skip blocks that contain only semicolons (empty statements) // These are trailing semicolons after return/raise/break statements // and are not actionable dead code if dcd.blockContainsOnlySemicolons(block) { return findings } // Determine the reason for the dead code reason, severity := dcd.determineDeadCodeReason(block) // Create a finding for this dead block finding := &DeadCodeFinding{ FunctionName: dcd.getFunctionName(), FilePath: dcd.getFilePath(), StartLine: dcd.getBlockStartLine(block), EndLine: dcd.getBlockEndLine(block), BlockID: block.ID, Code: dcd.getBlockCode(block), Reason: reason, Severity: severity, Description: dcd.generateDescription(reason, block), Context: dcd.getBlockContext(block), } findings = append(findings, finding) return findingsAssistant
Let me create and apply the fix properly:
Assistant
I need to properly create the fix file. Let me use a different approach to create and apply the fix cleanly.
Assistant
Now let me apply the patch:
Assistant
The patch was applied. Now let me verify the fix is correct by looking at the diff:
Assistant
The fix looks clean. Now let me verify it compiles and the tests pass:
Assistant
Good, it compiles. Now let me verify the fix works with the reproduction case:
Assistant
The fix works. Now let me run the tests to ensure nothing is broken:
Assistant
Let me also run the full test suite to make sure all tests pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && export GOPATH=/tmp/go && export GOMODCACHE=/tmp/go/pkg/mod && export GOCACHE=/tmp/go/cache && go test ./... 2>&1 | grep -E "^(ok|FAIL|?)" </tool_call>
Assistant
Let me run the full test suite to verify all tests pass.
Assistant
All tests pass. Let me clean up the temporary files and submit the fix.
<tool_call> <function=bash_terminal> <parameter=command> rm -f /tmp/pyscn /tmp/semi_repro.py && cd /pyscn && git status </tool_call>
Assistant
Let me check the git status and clean up any remaining files.
Assistant
Let me submit the changes now.
<tool_call> <function=submit> </tool_call>
Assistant
The submit tool call didn't work because it wasn't invoked properly. Let me invoke the submit function with the correct syntax.
Assistant
I need to use a special command format for the submit action. Let me try using the special submit command properly.
<tool_call> <function=bash_terminal> <parameter=command> submit </tool_call>
Assistant
Let me verify my fix one more time and then submit:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.