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 first inspect the repository structure and search for the dead-code analyzer and
unreachable_branchfinding construction. Then I’ll reproduce the reported behavior before making a focused source change. - Assistant
The implementation is in Go under
internal/analyzer. I’ll inspect the dead-code collection logic, related CFG/node types, and existing unit tests to identify the correct semantic filter point rather than filtering only the serializedcodestring. - Assistant
BasicBlock.IsEmptyonly checks statement count, so the semicolon’s parser node is counted as a statement. I’ll inspectBasicBlock, parser AST node metadata, CFG statement insertion, and code/location extraction to determine how an empty separator is represented reliably. - Assistant
The finding code falls back to
string(node.Type), explaining";". I need the exact AST type/constants and parser behavior. I’ll locate those definitions and run the CLI against a temporary reproduction file, keeping that file outside the repository so no test/source artifacts are added. - Assistant
The initial reproduction command is blocked by the environment having neither
GOMODCACHEnorGOPATH, not by the project. I’ll inspect the AST definitions/builder, then rerun with a temporary Go cache configuration. - Assistant
The AST has no explicit empty-statement constant; the reported
NodeTypeis literally";", likely from the generic tree-sitter fallback. I’ll inspect the completebuildNodedispatch and CFG suite processing, then reproduce with configured caches and inspect generated JSON. - Assistant
The dispatch confirms punctuation becomes a generic node, while module/block builders include every non-trivia child. Before deciding whether to fix parser normalization or dead-code filtering, I’ll inspect trivia handling and CFG termination behavior. I’ll also complete the reproduction with
GOCACHEset. - Assistant
The issue is reproduced: the report summary shows exactly two dead-code issues. I’ll extract the findings and inspect
isTrivia,buildBlock, and the generic CFG default. This will show whether semicolons should be excluded centrally at AST construction (likely safest, since they are grammar separators rather than Python statements) or only from dead-code reporting as requested. - Assistant
A parser-wide trivia change would alter AST shape for all consumers and would not directly satisfy dead-code behavior for manually constructed CFGs. I’ll therefore make the detector treat separator nodes as non-reportable while preserving real unreachable statements in the same block. Before editing, I’ll review dead-code tests for existing expectations around
pass, mixed blocks, and dead-block counts so the filter is narrowly scoped to synthetic";"nodes rather than realpassstatements. - Assistant
Existing tests count CFG statements directly and do not define
passas an empty synthetic separator. I’ll implement a narrow detector helper that removes only tree-sitter’s unnamed";"separator nodes.analyzeDeadBlockwill skip separator-only blocks and report real statements from mixed blocks with correct line/code selection.DeadBlocksandHasDeadCodewill be based on reportable findings so ignored separators do not leave phantom dead-code totals. - Assistant
The focused change is in place. I’ll now run the analyzer unit tests and rerun the exact reproduction, then inspect the generated report to ensure both the findings and dead-code issue count are zero.
- Assistant
The exact reproduction is fixed: the summary now reports
0 issues, and no";"/unreachable_branchfindings remain. I’ll validate the important mixed-block edge case (return; real_unreachable_statement) to confirm only the separator is removed—not actionable dead code—and then run the full Go test suite and static checks available throughgo test. - Assistant
The mixed-case output is correct (
code: "assignment"with no semicolon); my temporary assertion mistakenly expected line 3 even though that two-line fixture places the statement on line 2. The fullgo test ./...suite nevertheless completed successfully across all packages. I’ll rerun the edge assertion with the correct source line, perform formatting/diff checks, and inspect the final patch before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.