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
I'll start by exploring the repository structure to understand the codebase and locate relevant files for the dead-code analyzer. Let's begin.
- Assistant
Let me explore the repository structure more broadly to understand what we're working with.
- Assistant
This is a Go project (with some Python wrapper). Let me look at the Go source code for the dead-code analyzer.
- Assistant
Let me examine the dead code analyzer code to understand how it works.
- Assistant
Now let me look at the reachability analyzer and understand how blocks are built:
- Assistant
Let me look at the reachability analyzer and the CFG builder to understand how blocks are constructed and how empty statements are handled.
- Assistant
Let me look at the CFG builder and parser to understand how empty statements (bare
;) are handled: - Assistant
Let me look at the parser to understand how trailing semicolons are parsed.
- Assistant
Let me check the parser AST types to understand what happens with trailing semicolons.
- Assistant
Let me look for any node type related to empty statements or semicolons.
- Assistant
Let me look at the parser visitor to see how statements are parsed.
- Assistant
Let me look at the parser to understand how trailing semicolons are handled in Python. The issue says that
raise ValueError("nope");parses asraise Xfollowed by an empty statement. I need to understand how the parser handles this and how the CFG builder handles empty statements. - Assistant
Let me search for how the AST builder handles empty statements or semicolons.
- Assistant
Let me look at the AST builder to see if there's handling for empty_statement:
- Assistant
Let me first reproduce the issue with the suggested test file:
- Assistant
Let me check if pyscn is available as a command.
- Assistant
Let me find the main entry point.
- Assistant
Let me build the project first.
- Assistant
Let me check Go setup and environment.
- Assistant
Let me try setting GOPATH:
- Assistant
Need to set up more environment variables.
- Assistant
Good, the build succeeded. Now let me reproduce the issue. reproduced the error. Let me now understand how to fix it. The issue is in the dead-code analyzer that's reporting empty statements (caused by trailing semicolons) as unreachable code.
Let me trace through the code path:
- The
Detect()method in dead_code.go callsunreachableWithStatementswhich filters out blocks with no statements - Then it calls
analyzeDeadBlockfor each block - The
getBlockCodemethod creates a representation of the code - for a bare;it would produce ";" - The issue is that an empty statement (just a
;) is being reported as dead code
Let me look at how the parser handles this. In Python,
raise ValueError("nope");parses asraise ValueError("nope")followed by an empty statement. The empty statement becomes a separate block in the CFG.The fix should filter out blocks that only contain empty/pass-equivalent statements when collecting unreachable blocks.
Let me look at what the parser produces for
raise ValueError("nope");:Good, the build succeeded. Now let me reproduce the issue. - The
- Assistant
Let me run the repro test first.
- Assistant
Good, there are 2 dead code issues found. Let me look at the JSON report to see the actual findings.
- Assistant
Good, I've reproduced the issue. Now let me look at the full dead_code JSON and then understand the code flow. Let me check what the parser produces for the
raise X;statement: - Assistant
Let me look at the full dead code section:
- Assistant
Good, I've confirmed the issue. Now I need to understand the fix. The problem is that a trailing
;creates an empty statement block that follows araise/returnand is reported as unreachable. Let me look at how the CFG builder handles empty statements: - Assistant
Let me look at how tree-sitter handles the semicolon. Let me check the AST builder for handling of empty/semicolon nodes:
- Assistant
Let me see the full buildNode function to understand all handled node types:
- Assistant
Now let me look at how the CFG builder processes statements and specifically how it handles empty statements:
- Assistant
Let me look at the full
buildNodeand how the CFG builder processes statements to understand how an empty;statement becomes a block: - Assistant
Let me look at the processStatement function to understand how it handles different statement types, especially the Pass statement and what happens with empty statements.
- Assistant
Let me see the full processStatement to understand the default case:
- Assistant
Now let me look at how the parser handles raise_statement to understand the structure:
- Assistant
Let me write a quick test to see how tree-sitter parses the
raise X;statement: - Assistant
Now I understand the issue. The tree-sitter parser produces the
;as a bare token (type;) in the block after the raise statement. Let me check how this is handled in the AST builder: - Assistant
I can't use internal packages outside the module. Let me trace the code instead. The key is understanding how
;(tree-sitter's empty_statement or bare;) gets handled: - Assistant
Let me check isTrivia:
- Assistant
Let me look at the
buildBlockfunction in the AST builder: - Assistant
Let me see the buildBlock function:
- Assistant
Now I understand the full picture. Let me look at how the dead-code detector processes the unreachable block to understand the exact fix needed. Let me check how the
getBlockCodehandles the;node: - Assistant
Now I understand the full picture. Let me understand the exact problem:
raise ValueError("nope");has a trailing;that tree-sitter produces as a bare;token in the block- The AST builder's
buildBlockcallsbuildNodefor the;token, creating a node with type; - The CFG builder adds this
;node to the current block (after a raise, which creates an unreachable block) - The dead code detector reports this as unreachable dead code with
code: ";"and0-0column range
The fix should filter out empty/no-op statements. Let me look at what node type the
;creates in the AST builder default case: - Assistant
Now let me understand the exact node structure. Let me check what
buildBlockdoes with the;: - Assistant
Let me understand the full flow better. Let me look at how the reachability analyzer reports blocks:
- Assistant
Let me look at the
IsEmptyfunction: - Assistant
Now I understand the full flow. The issue is:
raise ValueError("nope");→ tree-sitter sees the;as a bare child of the block- The AST builder's
buildBlock→ callsbuildNodefor;→ creates a node with type; - The CFG builder adds this
;node to the unreachable block after raise - The dead code detector reports it
Let me now look at the existing tests to understand the expected behavior:
- Assistant
Now let me look at the service layer that formats the dead code findings to understand the column 0-0 issue:
- Assistant
Let me understand how the raise statement is processed in the CFG builder:
- Assistant
Let me look at
processRaiseStatement: - Assistant
Now I understand the full flow. Let me look at the
DeadCodeFindinglocation and how columns are populated: - Assistant
Let me look at the dead code service that converts analyzer findings to domain findings:
- Assistant
Now I have a complete understanding of the issue. Let me trace the flow:
raise ValueError("nope");→ tree-sitter sees;as a bare token in the blockbuildBlockin the AST builder creates a node with type;- The CFG builder processes it in the
defaultcase ofprocessStatement, adding it to the unreachable block after the raise - The dead code detector reports it as unreachable dead code
The fix should be in the dead code detector to skip blocks that contain only empty/no-op statements. Let me implement the fix:
- Assistant
Now I understand the issue completely. The fix should be in the dead code detector to skip blocks that contain only empty/no-op statements (like bare
;tokens). Let me implement the fix: - Assistant
Now I have a complete understanding. The fix should be in the dead code detector's
analyzeDeadBlockmethod to skip blocks that contain only empty/no-op statements (like bare;). Let me implement the fix: - Assistant
Now I understand the complete flow. The fix should be in the dead code detector to skip blocks that contain only empty/no-op statements (like bare
;tokens). Let me implement the fix. I need to add a check inanalyzeDeadBlockto filter out blocks whose statements are all no-ops: - Assistant
Let me use the special edit command format:
- Assistant
I notice the edit may have removed part of the function. Let me check the full state around the edit:
- Assistant
I see the edit accidentally removed the body of
analyzeDeadBlock. Let me fix that: - Assistant
I need to add a blank line between the two functions:
- Assistant
I need to add a blank line between the two functions:
- Assistant
Let me add a blank line between the functions for style consistency:
- Assistant
Good. Now let me build and test the fix:
- Assistant
Good, it compiles. Let me run the reproduction test:
- Assistant
Dead Code now shows 100/100 with 0 issues. Let me verify the JSON output:
- Assistant
Let me look at the JSON more carefully.
- Assistant
Let me look at the raw JSON:
- Assistant
The fix works - no more dead code findings for the trailing semicolons. Now let me run the existing tests to make sure nothing is broken:
- Assistant
All dead code tests pass. Let me run the broader test suite:
- Assistant
All analyzer tests pass. Let me also run the service-level dead code tests:
- Assistant
All tests pass. Let me also run the full test suite and test edge cases:
- Assistant
Let me create a better edge case test:
- Assistant
2 issues found (1 critical). Let me verify these are only the real dead code cases:
- Assistant
The fix is working correctly:
- Functions
fandg(with only trailing;) - NOT reported (correctly filtered out) - Function
h(with;+ real dead codex = 1) - still reported (correct, real dead code detected) - Function
j(real dead code after return) - still reported (correct)
Now let me run the full test suite to make sure nothing is broken:
- Functions
- Assistant
All tests pass. Let me now verify the changes I made:
- Assistant
The diff is clean and minimal. Let me also do a final check that the fix handles the exact repro case from the issue:
- Assistant
The fix works perfectly. Let me now run the full test suite one final time to be thorough:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.