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 understand the issue:
- The dead-code detector in
pyscnreports unreachable code warnings for trailing semicolons (;) which create empty statements. - In Python,
raise X;creates araise Xstatement followed by an empty statement. The empty statement is technically unreachable, but reporting it is noise. - The fix should skip CFG nodes that correspond to empty statements when collecting unreachable-branch findings.
Let me explore the repository structure first.
- The dead-code detector in
Assistant
Let me look at the source code more carefully. This is a Python project called pyscn. Let me find the relevant dead code analysis files.
Assistant
Hmm, the source code seems very small. Let me look at the main files.
Assistant
Let me do one command at a time.
Assistant
This is a Python wrapper around a Go binary. The actual logic must be in the Go source code. Let me find it
Assistant
Let me look at the dead code related files - both the service and the config loader.
Assistant
Now let me find the analyzer package that does the actual dead code detection.
Assistant
Let me look at the dead code analyzer and CFG builder files
Assistant
Now let me look at the reachability analyzer, especially the
GetUnreachableBlocksWithStatementsmethodAssistant
Let me look at the CFG builder and the
IsEmpty()method to understand how blocks are created.Assistant
Let me look at the
IsEmpty()method and theBasicBlockstructure. Let me also find howprocessStatementhandles empty statements.Assistant
Look at the
IsEmptymethod and the BasicBlock structureAssistant
Let me look at the parser to find what node types exist and how empty statements (trailing
;) are handled.Assistant
Let me look at the parser's visitor to understand how semicolons and empty statements are handled.
Assistant
Let me look at the AST builder, which creates AST nodes from tree-sitter's parse tree.
Assistant
Let me look at the
buildExpressionStatementfunction in the AST builder.Assistant
Look at the expression statement building function.
Assistant
Let me look at
processStatementin the CFG builder to see how it handlesNodeExpr.Assistant
Let me look at
processStatementand how it handlesNodeExpr.Assistant
Let me look at the dead code test file to understand existing test cases and how to verify my fix.
Assistant
Let me look at the domain model for dead code findings.
Assistant
Look at the domain dead_code.go
Assistant
Let me check what
NodeExpris used for throughout the codebase, to understand the impact of filtering empty expression statements.Assistant
Let me look at the apted_tree.go reference and the ast.go line 271.
Assistant
Let me look at ast.go around line 271.
Assistant
Let me first try to reproduce the issue. Let me look at how tests are run and try to create a simple reproduction.
Assistant
Let me set up the Go environment properly.
Assistant
Let me set up Go environment variables and try again.
Assistant
Good, now let me run the tests.
Assistant
Let me set all required Go environment variables.
Assistant
Good, existing tests pass. Now let me write a quick Go test to reproduce the issue with trailing semicolons.
Assistant
Let me rename the file and try again.
Assistant
Let me create the repro script inside the project instead.
Assistant
Let me create the directory first.
Assistant
I've confirmed the bug. Now let me implement the fix. The best approach is to fix
buildExpressionStatementin the AST builder to returnnilfor empty expression statements (like bare;). Let me look at the function again and make the changeAssistant
Now I'll make the fix. The issue is in
buildExpressionStatement- it should returnnilfor empty expression statements (bare;), rather than creating an emptyNodeExpror a node with type `";"Assistant
Now let me verify the fix by running the reproduction script.
Assistant
The fix didn't work. Let me debug more to understand the tree-sitter node structure.
Assistant
Let me verify the edit took effect and debug the tree-sitter node types.
Assistant
Let me debug more - let me check what the tree-sitter node structure looks like.
Assistant
Let me look at the parser to understand how tree-sitter is used.
Assistant
Let me debug by walking the raw tree-sitter tree to see what nodes the
expression_statementcontains.Assistant
Now I understand the issue. The
;is a direct unnamed child ofmodule(not insideexpression_statement). The fix needs to be inbuildModuleand similar functions that iterate over children. Let me fix those.Assistant
Let me fix the grep.
Assistant
Let me look at the default case in
buildNodeand the key body-processing functions.Assistant
Find the default case in buildNode.
Assistant
Let me look at line 191 area.
Assistant
Now I understand the full picture. The
;is an unnamed token in tree-sitter that becomes a direct child of the module/function body. I need to fix this in two places:- Add
child.IsNamed()checks to body-processing functions - Return
nilin the default case ofbuildNodefor unnamed nodes
Let me look at the body-processing functions first
- Add
Assistant
Let me also look at the other body-processing functions.
Assistant
Let me check if the
;also appears as direct child in a function body.Assistant
Let me look at
buildBlockto see how it processes block children.Assistant
Let me look at buildBlock.
Assistant
Now I understand the full issue. The fix should be in the default case of
buildNode: returnnilfor unnamed nodes, since they are not meaningful AST constructs (they are just punctuation/keywords). Let me make this fix.Assistant
I need to fix the duplicate
return nodeline.Assistant
Now let me verify the fix by running the reproduction script.
Assistant
Let me run the actual dead code detection repro script to verify the fix
Assistant
The fix works. Now let me run the existing tests to ensure nothing is broken.
Assistant
Parser tests pass. Now let me run the analyzer tests.
Assistant
Some tests failed. Let me see the full output.
Assistant
Let me look for the FAIL lines specifically.
Assistant
Only one test failed. Let me look at it to understand what's happening.
Assistant
Let me look at this test.
Assistant
Let me see the test code.
Assistant
Let me look at the module analyzer to understand abstract class detection.
Assistant
Let me look at lines 666-700 to understand abstract class detection.
Assistant
Let me look at
isAbstractClassfunction.Assistant
Let me check if this test failure is pre-existing by stashing changes and running the test
Assistant
Let me restore my changes and debug the
Assistant
Let me debug which class is being missed by writing a quick diagnostic script.
Assistant
Let me look at how the class definition processes its bases, specifically
buildClassDefandbuildArgumentList.Assistant
Let me look at
buildArgumentList.Assistant
Let me look at
nodeQualifiedNameto see how it handles thekeyword_argumentnode type.Assistant
I see the problem. My change to
buildNode's default case breakskeyword_argumentparsing which relies on unnamed nodes being present as children at specific positions. Let me revert that change and instead fix the body-processing functions to skip unnamed childrenAssistant
I need to revert the
buildNodechange and instead fix the body-processing functions. The;is a direct child ofblock/module, not insideexpression_statement.Assistant
Now let me apply the correct fix. I'll modify
buildBlockandbuildModuleto skip unnamed children, and also fixbuildExpressionStatementto return nil for empty statements.Assistant
Let me apply the fix to the body-processing functions.
Assistant
Let me fix the duplicate
return nodeand also fixbuildBlock.Assistant
Now let me find and fix
buildBlock.Assistant
Let me view and fix buildBlock
Assistant
Now fix
buildBlockto skip unnamed children.Assistant
Now let me also fix
buildExpressionStatementto return nil for empty expression statements.Assistant
Let me also fix
buildExpressionStatementfor safety.Assistant
Now let me verify the fix works.
Assistant
That's the diagnostic script - let me update it to test the actual issue.
Assistant
The fix works - no dead code findings for trailing semicolons. Now let me run the full test suite to make sure nothing is broken.
Assistant
All analyzer tests pass. Let me run all tests.
Assistant
All tests pass. Let me clean up the temporary repro script and review the final diff.
Assistant
Let me run the dead code detection tests one more time to be sure.
Assistant
All dead code tests pass. Let me also verify the previously-failing test passes now.
Assistant
Summary
Here's a summary of the changes I made:
Problem
The dead-code detector was reporting
warning-severityunreachable_branchfindings for trailing semicolons (;). In Python,raise X;is valid syntax that creates araisestatement followed by an empty statement (the;). The empty statement was being parsed as a tree-sitter node, added to the AST, built into a CFG block, and then flagged as unreachable dead code.Fix
Modified
/pyscn/internal/parser/ast_builder.goin three places:-
buildBlock(line 1684): Addedchild.IsNamed()check to skip unnamed tree-sitter nodes (like;) when processing block body statements. -
buildModule(line 217): Addedchild.IsNamed()check for the same reason when processing module body statements. -
buildExpressionStatement(line 793): Addedchild.IsNamed()check and returnsnilinstead of creating an emptyNodeExprwhen no named expression child exists. This handles the edge case where a bare;might be wrapped in an expression statement node.
These changes prevent unnamed punctuation tokens (like
;) from being added to the AST as standalone statements, which in turn prevents them from being flagged as unreachable dead code by the analyzer.Verification
- ✅ Reproduced the bug with a Go test script
- ✅ Confirmed the fix eliminates the false positive findings
- ✅ All existing tests pass across the entire project
-
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 →