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 then find the relevant code for the dead-code analyzer. The issue is about trailing semicolons being reported as unreachable branches. I need to:
- Explore the repository structure
- Find the dead-code detection code
- Create a reproduction script
- Implement the fix
- Verify the fix
Let me start by exploring the repository.
Assistant
This seems to be a Rust project (based on the name "pyscn" which might be a Python scanner). Let me look at the repository structure more carefully.
Assistant
It's a Go project. Let me look for the dead-code detection
Assistant
Let me look at the key files for dead-code detection and CFG building.
Assistant
Let me use bash_terminal to open the file.
Assistant
Let me scroll through the file to find where unreachable branches are detected.
Assistant
Let me look around line 222 where
ReasonUnreachableBranchis set and the broader context of finding collectionAssistant
Let me look at the reachability analyzer and the
GetUnreachableBlocksWithStatementsAssistant
Let me look at the
GetUnreachableBlocksWithStatementsfunction in reachability.goAssistant
So the filtering uses
block.IsEmpty(). Let me look at howBasicBlockandIsEmpty()are implementedAssistant
Let me understand the parser structure for empty statements (
;).Assistant
Let me look at the AST node types to understand what an empty statement looks like.
Assistant
Let me look at the CFG builder to understand how statements are assigned to blocks, especially around returns/raises.
Assistant
Let me understand how empty statements from
;are represented in the AST. Let me search the parser for how semicolons are handled.Assistant
Let me first create a reproduction script and run the tool to confirm the bug
Assistant
Now let me check if there's a binary we can run to test.
Assistant
Let me set up Go environment first
Assistant
Let me set up all the needed Go environment variables.
Assistant
Good, the build succeeded. Now let me run the reproduction script.
Assistant
Let me check the generated JSON report.
Assistant
I've confirmed the bug. The
;is being reported as dead code withcode: ";"and0-0column range. Let me see the full dead code outputAssistant
Let me look at the full findings.
Assistant
Let me understand how the empty statement
;is represented in the AST. Let me write a quick test.Assistant
Let me write a test within the package to understand the AST.
Assistant
Let me check the parser API.
Assistant
Let me clean up and look at how parsing works in the test files.
Assistant
Let me look at the existing dead_code test to understand how parsing works in tests.
Assistant
Let me look at the helper functions in the test.
Assistant
Let me see the test function body to understand how code is parsed.
Assistant
Let me look at how the
codefield is populated inanalyzeDeadBlockAssistant
Let me find the
getBlockCodemethod:Assistant
Let me look at these functions.
Assistant
Let me look at how the CFG builder processes statement lists/body.
Assistant
Let me look at how the CFG builder processes body/block statements.
Assistant
Let me look at the AST builder to understand what node
;becomes.Assistant
Let me search for expression_statement handling in the AST builder
Assistant
Let me look at the
buildExpressionStatementfunction.Assistant
Let me look at the
isTriviafunction in the AST builder.Assistant
Let me look at this function.
Assistant
Let me look at the Node structure to understand the Value field.
Assistant
Let me look at the Node struct.
Assistant
Let me look at how the
codefield is generated in the service layer. The;in the output might come from a different code path.Assistant
Let me search for where the analyzer's
DeadCodeFindingis converted to the domain's representation.Assistant
Let me write a test to dump the actual AST for understanding.
Assistant
Let me look at how
buildNodehandles unknown node types like;.Assistant
Let me look at the default case in
buildNodearound line 191.Assistant
Let me see the default case around line 191.
Assistant
Now I understand the issue. The tree-sitter parser creates a node with type
";"for trailing semicolons. In thebuildNodedefault case, this becomes aNodeType(";")node. The fix should be to return nil for;nodes inbuildNode, so they get filtered out.Let me implement this
Assistant
Now let me rebuild and test.
Assistant
Now let me test with the reproduction script.
Assistant
Let me check the raw output format.
Assistant
Dead code is now 100/100 with 0 issues! Let me verify the JSON report.
Assistant
Let me check the full dead_code section.
Assistant
The fix works - 0 dead code findings. Now let me run existing tests to make sure nothing is broken.
Assistant
Parser tests pass. Let me run the analyzer tests.
Assistant
All tests pass. Let me also specifically run dead code related tests.
Assistant
All dead code tests pass. Let me run the service and app tests as well.
Assistant
All tests pass! Let me clean up the debug test file.
Assistant
Let me test edge cases to make sure the fix is robust.
Assistant
Let me check the report file path instead.
Assistant
Let me read the report.
Assistant
This is perfect! Let me verify against the original repro:
- f1, f2: Trailing semicolons after
raise/returnare now filtered out (no false positives) - f4: Real dead code after a semicolon-terminated return is still properly detected
- f5:
passstatement afterreturnis still detected as dead code
Let me also verify by running the original repro exactly.
- f1, f2: Trailing semicolons after
Assistant
The fix is confirmed working. Let me now review 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 →