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
Let me explore the repository structure to understand the codebase.
Assistant
Let me look at the reachability analyzer and how empty statements are handled. Let me find the
GetUnreachableBlocksWithStatementsmethod.Assistant
Let me look at the
IsEmpty()method and the parser node types.Assistant
Let me reproduce the issue first.
Assistant
I've reproduced the issue. Now let me understand how the empty statement from
;is parsed. Let me look at the parser and how the;becomes a node.Assistant
Now let me understand how the
;is parsed into a node. Let me look at the parser/ast_builder for empty statements.Assistant
Let me write a debug script to dump the CFG blocks to understand the empty statement node structure.
Assistant
Let me write a Go test to dump the CFG blocks for the repro file to see the node structure of the empty statement.
Assistant
Let me look at how
NodeExpr(empty statement from;) is processed and added. Let me check the default case.Assistant
Let me look at how the parser is used to build CFGs from source to write a proper debug test.
Assistant
Now let me write a proper debug test.
Assistant
The JSON output structure differs from
DeadCodeFinding. Let me check the service layer that produces the final JSON.Assistant
Let me fix the debug test to print the node types.
Assistant
The empty statement has
Type == ";". Let me look at how this node is built in the parser to understand it better.Assistant
The empty statement node has
Type == ";". Let me check the tree-sitter grammar to confirm the exact node type and see if there's a cleaner constant. Let me check how the visitor/tree-sitter handles it.Assistant
Let me write a test to print the raw tree-sitter node type for the empty statement to be certain.
Assistant
The
;is an anonymous node. Let me walk all children (including anonymous).Assistant
Now let me look at
buildBlockto see how the;becomes a statement in the body.Assistant
Let me check imports and usages of
IsEmptyandGetUnreachableBlocksWithStatements.Assistant
Let me check
buildModuleand how the module-level body is built (for top-level;).Assistant
Let me check existing tests and testdata that might involve
;or empty statements.Assistant
Let me check the tree structure for
a = 1; b = 2(inline semicolons) to ensure my fix won't break metrics.Assistant
Let me look at the dead-code analyzer tests to understand expectations.
Assistant
Now I understand the root cause. The bare
;(anonymous tree-sitter node) is treated as a statement node (Type == ";") and added to CFG blocks. After areturn/raise, the CFG builder creates an empty "unreachable" block; the trailing;populates it, making it pass the!IsEmpty()filter and get reported as dead code.Let me implement the fix at the parser level — dropping no-op empty statements so they never enter the AST/CFG. This aligns with CPython's
astmodule (which produces no node for trailing;).Assistant
Let me check if any tests assert on the
;node or empty statements before making the parserchange.Assistant
No tests rely on the
;node. Let me implement the parser fix.Assistant
Now let me rebuild and verify the repro is fixed.
Assistant
The Dead Code score is now 100/100 with 0 issues. Let me verify the JSON structure properly.
Assistant
The fix works — 0 findings, 0 dead_blocks, 0 suggestions. Now let me run the existing test suites to ensure nothing breaks.
Assistant
All tests pass. Let me test some edge cases to be thorough.
Assistant
The edge file has a syntax error somewhere. Let me identify which constructs are valid Python.
Assistant
return z;;is a genuine CPython syntax error. Let me remove it and test the valid constructs.Assistant
Excellent! The behavior is now correct:
f,g: no findings (trailing;after raise/return dropped).inline(a = 1; b = 2): both real assignments remain, no false positive.pass;: no finding.after(return zthenfoo(); bar()): the real unreachable calls are still correctly reported (Call\nCall), but the trailing;no longer pollutes the code string.
Let me run the broader test suite to confirm nothing else breaks.
Assistant
The parser fix resolves the issue and all tests pass. To align with the issue's suggested fix location and provide defense-in-depth (e.g., for directly-constructed CFGs), I'll also add an explicit empty-statement filter in the dead-code analyzer. Let me view the relevant section.
Assistant
Now let me add the empty-statement filter in
analyzeDeadBlockand helper methods.Assistant
Let me also make the dead-block count consistent with the filter. Let me view the
Detectloop.Assistant
Let me rebuild and run the tests plus the repro.
Assistant
Let me force a clean re-run (no cache) to be sure the new dead_code.go changes pass.
Assistant
Now let me re-verify the repro and the edge cases with the final build.
Assistant
The repro is fully fixed (0 findings) and real unreachable code is still detected. Let me check git status to review my changes and ensure no stray files.
Assistant
Let me review the final diffs.
Assistant
The diff is clean. Let me run the full test suite across all packages to be thorough.
Assistant
Let me test a couple more tricky edge cases: a function body consisting only of
;, andifbodies with;.Assistant
def f(): ;is a CPython syntax error, so not a concern. Let me test only the validif_then_semicase.Assistant
Everything works correctly. Let me clean up temporary files and do a final verification of the git state.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.