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.
pyscn version:
v1.22.5(commitbac7f16)Found via the FP-audit skill in repo
bioconvert/bioconvert@92f4655(4 real occurrences:bioconvert/utils/biocode/gff.py:618,tbl.py:114,things.py:753and:780).ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /pyscn, current file: none) bash-$
Assistant
Let me start by understanding the repository structure and the issue. The issue is about a dead-code detector in pyscn that reports trailing semicolons as unreachable branches. Let me explore the repository first.
Assistant
This is a Go project (pyscn). Let me look at the structure more.
Assistant
Let me find the dead-code related files.
Assistant
Let me look at the key files. First, let me understand the dead code analyzer and the reachability analysis
Assistant
Now let me look at the dead_code.go file to understand how dead code findings are collected.
Assistant
Let me look at the BasicBlock and CFG builder to understand how empty statements are handled:
Assistant
Let me check the CFG and BasicBlock types
Assistant
Let me look at the BasicBlock and its IsEmpty method.
Assistant
Now let me look at the parser's node types to understand what "empty statement" looks like:
Assistant
Let me look at the parser's AST definitions to find what node types exist.
Assistant
Let me search for how semicolons are handled in the parser and AST builder.
Assistant
Let me look at the reachability test for empty blocks and also understand how the CFG builder processes statements - specifically how it handles separator/expression
Assistant
Let me look at the AST builder to understand how statements are built and how semicolons are handled:
Assistant
Let me look at the ast_builder.go around the expression_statement handling and around line 798.
Assistant
Let me look at the buildExpressionStatement function and also how suite/statement_list is processed
Assistant
Let me look at the buildExpressionStatement function.
Assistant
Let me first reproduce the issue to confirm it
Assistant
Now let's run pyscn on this file to reproduce the issue.
Assistant
Let me check the build setup.
Assistant
Let me check if Go is available and set up the environment.
Assistant
Now let's run the reproduce script:
Assistant
Let me check the generated JSON report.
Assistant
Let me understand the CFG builder's processStatement to see how expression statements are handled
Assistant
Let me look at the processStatement function to see how it processes different node types.
Assistant
Let me see the rest of the processStatement switch
Assistant
Let me look at the dead_code_formatter.go to see how the code field is populated from the findings.
Assistant
Let me look at the dead_code_usecase.go to understand how findings are mapped from analyzer to domain
Assistant
Let me look at the dead_code_service.go to see how findings are mapped.
Assistant
Let me investigate what tree-sitter creates for a trailing semicolon by writing a debug
Assistant
Let me put the debug script inside the repo instead
Assistant
Excellent! Now I can see the issue. Tree-sitter creates a node with
Type=";"for the trailing semicolon. This is not any of the known node types, sogetNodeDescriptionreturnsstring(node.Type)=";".Let me check if there's a constant for this node type in the parser:
Assistant
Let me look at how the
;node is built in the AST builder:Assistant
Let me look at the
buildNodefunction in ast_builder.go to understand how;node is handled.Assistant
Let me look at the
buildNodefunction starting at line 61 to see how it handles the;type.Assistant
Let me look at the default case in buildNode.
Assistant
Let me look at the default case around line 191.
Assistant
Let me find how processStatement handles the default case / unknown node types.
Assistant
Let me look at all usages of
IsEmpty()in the codebase to understand the impact of changingAssistant
Now I have a clear understanding of the issue. The tree-sitter parser creates
;nodes (type";") for trailing semicolons. These get added to CFG blocks, and when a block with only a;is unreachable (after a raise/return), it gets reported as a dead code finding.The fix should be in
BasicBlock.IsEmpty()to treat blocks with only no-op statements (like;) as empty. This way, they'll be filtered out byGetUnreachableBlocksWithStatements().Let me first clean up my debug file and implement the fix:
Assistant
Now let me implement the fix. Let me open the cfg.go file at the
IsEmptymethod.Assistant
Let me use the open command properly.
Assistant
Now let me modify the
IsEmpty()method to treat;nodes as no-op statementsAssistant
Let me try using replace instead.
Assistant
Let me use sed directly to make the change
Assistant
Let me verify the change was applied correctly
Assistant
Good, the change is applied. Now let me rebuild and test
Assistant
Build succeeded. Now let me test with the reproduction script.
Assistant
Dead Code score is now 100/100 with 0 issues. Let me verify the JSON report to confirm the findings are gone.
Assistant
The total findings is 0 - the fix works. Let me also run the standalone dead code analysis to verify
Assistant
Let me test some edge cases to make sure the fix is robust.
Assistant
Let me fix the test file - multiple semicolons are not valid Python
Assistant
1 finding - that should be the real unreachable code in f1. Let me check the JSON to confirm.
Assistant
The fix works correctly:
- f1: Real unreachable code after raise is still reported (critical, line 5) ✅
- f2, f3: Trailing semicolons after raise/return are filtered out ✅
- f4, f5: Semicolons in normal code don't cause false positives ✅
Now let me run the existing tests to make sure nothing is broken.
Assistant
All analyzer tests pass. Let me also run the service and domain tests related to dead code.
Assistant
Let me also run the full test suites for the relevant packages
Assistant
All tests pass. Let me also run the service tests.
Assistant
All tests pass. Let me verify the changes I've made.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →