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):pythondef f(x): if x is None: raise ValueError("nope"); return x def g(y): return y;Run:
bashpyscn analyze --json --no-open semi_repro.pyActual output
Two dead-code findings (from the generated JSON report):
json{"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 — a that points at literal with a column range reads as a real defect when there is none. Bounded impact: only fires on the rare trailing-semicolon style.
Assistant
Let me start by exploring the repository structure to understand what we're working with.
Assistant
This is a Go-based repository for a Python analysis tool. Let me explore the structure more.
Assistant
Let me explore the parser package to find out how empty statements are represented.
Assistant
Let me search for "empty" or related concept in theparser.
Assistant
Let me look more at the parser file to understand.
Assistant
Let me first reproduce the issue.
Assistant
I've successfully reproduced the issue. Now let me investigate the CFG builder to understand how empty statements are handled.
Assistant
Let me look at the ast_builder for empty statements.
Assistant
Let me see how the parser actually handles a simple statement like
raise ValueError("nope");.Assistant
Let me try a different approach: build the test inside the pyscn repository so it can access internal packages.
Assistant
Let me look more carefully at how the AST builder handles these
;nodes.Assistant
So the
;is coming from tree-sitter as a node. The NodeType is;(literal semicolon). The parser creates a generic node withNodeType(nodeType)=NodeType(";").Now let me look at how the block parser processes these. Looking at how the tree-sitter handles
raise ValueError("nope");— it likely produces ablockwith multiple statements separated by semicolons, and the tree-sitter treats;as a "block" or something. Let me search for "block" or howthis gets into the body.Assistant
Now let me see how the CFG builder handles these
;nodes:Assistant
Let me look at where the unreachable block is generated and find the dead_code path:
Assistant
Now let me look at the BasicBlock and dead_code structure:
Assistant
Let me investigate why the column range is 0-0 in the output:
Assistant
Now let me look at the existing tests to understand what's already being tested:
Assistant
Let me look at the tests more carefully and understand what behaviors are being tested:
Assistant
Now I have a good understanding. Let me look at the
getUnreachableBlocksWithStatementsfunction to understand how blocks are identified:Assistant
Let me check more about how
getNodeDescriptionhandles the unknown node type for the;:Assistant
Let me also verify the
;is what tree-sitter produces by checking with raw tree-sitter:Assistant
Let me look at how
passis handled currently to make sure my understanding is correct:Assistant
Now I have a complete understanding. Let me clean up the test parser and implement the fix:
Assistant
Now let me implement the fix in
dead_code.go:Assistant
Now let me apply the fix. First, I'll modify
analyzeDeadBlockto skip blocks with only empty statements, then I'll add helper functions:Assistant
Let me try the edit differently - using the search/replace format:
Assistant
The file uses tabs for indentation. Let me use the propertab-based replacement.
Assistant
Now let me also modify
getBlockCode,getBlockStartLine, andgetBlockEndLineto skip empty statements for more accurate findings:Assistant
Let me also modify
getBlockCodeto skip empty statements when generating the code description:Assistant
Now let me add the helper functions. I'll place them at the end of the file before any closing:
Assistant
Now let me build the project and test the fix:
Assistant
The fix works for the simple case. Now let me test edge cases:
Assistant
Let me try a better test where the dead code is real:
Assistant
The
;is correctly filtered. Let me also test thepassmixed case:Assistant
Let me check if
getBlockStartLine/getBlockEndLineis used elsewhere:Assistant
These methods are only used internally. Let me update them to also skip empty statements:
Assistant
The output is empty for the dead code section. Let me verify by looking at the jsonfile directly.
Assistant
Now line range is correctly 5-5 (just the print). Let me test with
passmixed:Assistant
Let me also test with real dead code to make sure we still flag it:
Assistant
Real dead code is still detected. Let me test
passalone:Assistant
Let me check the existing tests to see if any rely on
passafter return being flagged:Assistant
Let me run the existing tests to make sure nothing is broken:
Assistant
All existing dead code tests pass. Let me also run the broader test suite:
Assistant
All tests in the analyzer package pass. Now let me also run the parser tests:
Assistant
Let me also run the service tests:
Assistant
Excellent! All tests pass. Now let me write a temporary test script to verify all the edge cases:
Assistant
All edge cases pass. Let me look at the final state of my changes:
Assistant
Let me also test a case that matches the bioconvert pattern:
Assistant
Let me also test some additional edge cases:
Assistant
Let me test a more pathological case:
Assistant
Let me investigate why the print isn't being detected:
Assistant
Ah,
;;;;is a syntax error in Python. Tree-sitter requires proper syntax. So this case isn't valid Python. Let me try with just a single;between.Assistant
Even with
;on separate lines, that's a syntax error. Let me test with valid Python:Assistant
Let me clean up and test more focused cases:
Assistant
All edge cases work correctly. Let me clean up and verify once more:
Assistant
Good, all temp files are cleaned up. Let me run the tests once more to make sure everything passes:
Assistant
All tests pass. Let me also make a final reproduction test using the exact example from the issue:
Assistant
The fix works correctly. The original bug report shows 2 false-positive findings; with the fix, there are 0 findings.
Let me clean up and do a final review:
Assistant
Let me run one final check to confirm everything works:
Assistant
The fix is working correctly. Let me also check that no other tests are broken:
Assistant
All tests pass. Let me provide a final summary of my changes:
Summary
The bug was that the dead-code detector emitted false-positive
unreachable_branchfindings withcode: ";"whenever a Python file contained areturn/raisestatement with a trailing semicolon (e.g.return x;orraise ValueError("nope");). Tree-sitter parses the trailing;as a separate empty-statement node, which then gets added to the unreachable block after the terminator and gets flagged as dead code.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.