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, CFG node handling, and existing tests around unreachable branches. Then I’ll reproduce the reported output before making a focused filtering change.
- Assistant
The implementation is in
internal/analyzer/dead_code.go. I’ll inspect its CFG traversal and related unit tests, plus parser node APIs, to identify the most robust definition of an empty semicolon node rather than relying only on malformed coordinates. - Assistant
The detector currently emits one finding per unreachable block without checking statement content, and
getNodeDescriptionfalls back to the raw node type (hence";"). I’ll inspectparser.Node, tree-sitter conversion, CFG construction, and dead-code test helpers to see whether empty statements have a dedicated type and whether mixed blocks require filtering individual statements. - Assistant
There is already an established semicolon-node predicate in
raw_metrics.go, confirming the parser represents separators asNodeType(";"), notNodePass. I’ll inspect that usage and the CFG statement-processing path, then reproduce through the project’s actual CLI/build flow. - Assistant
The bug could be prevented either during CFG construction or finding collection. The issue specifically requests filtering before findings; that is safer because changing CFG topology may affect control-flow behavior. I’ll now build the CLI, run the exact repro from
/tmp, and inspect the generated report to establish the baseline. - Assistant
The first reproduction attempt was blocked by an environment-only Go configuration issue (
GOMODCACHEandGOPATHare both unset), not by the repository. I’ll set a temporary GOPATH explicitly, rebuild from the repository root, and rerun without modifying repository configuration. - Assistant
Go also requires a build-cache path because this sandbox has no
HOME; I’ll supply both temporary paths and proceed with the same baseline reproduction. - Assistant
The binary now builds successfully; the repro file was never created because the earlier chained command stopped at the first build failure. I’ll recreate it and capture the report location/content.
- Assistant
The exact two false positives are reproduced. A finding-only guard in
analyzeDeadBlockwould remove the entries, butDeadBlocksis currently counted before filtering andDetectInFileincludes results whenDeadBlocks > 0; this could still inflate dead-code summary metrics. I’ll trace consumers ofDeadBlocksand statement grouping so the fix removes noise consistently while preserving genuine unreachable statements that might share a block with separators. - Assistant
DeadBlocksdirectly drives ratios and summaries, so merely suppressing the finding would leave a false issue count. The clean detector-level design is to define a reportable-statement predicate, filter unreachable blocks to those containing at least one reportable statement, and generate location/code from the filtered statements. This handles both separator-only blocks and the edge casereturn; real_call()in one unreachable block. I’ll inspect the parser’s generic-node conversion to ensure only semicolon nodes—notpass, which is a real explicit statement—are classified as empty separators. - Assistant
The CFG default intentionally admits punctuation nodes, while parser conversion uses the raw tree-sitter type for unknown nodes. I’ll inspect that conversion and then implement a local dead-code predicate for
";"(matching the repository’s existingisLogicalSeparator) rather than broad coordinate-based filtering that could hide malformed but actionable nodes. - Assistant
I’ll implement detector-level filtering with three properties: nil and
";"statements are non-reportable; separator-only unreachable blocks do not incrementDeadBlocksor emit findings; and mixed blocks derive code/location from reportable statements only. I’ll also alignHasDeadCodewith this filtering so API callers don’t get contradictory results. No parser or CFG semantics will change. - Assistant
The focused change is in place. I’ll run the analyzer unit suite, rebuild, and rerun the exact CLI repro. I’ll also use a temporary edge-case source containing both trailing separators and genuine same-line unreachable code to verify separators are omitted without suppressing actionable findings.
- Assistant
The exact repro is fixed: zero findings and zero dead blocks, and analyzer tests pass. My temporary edge source accidentally used
;;, which Python correctly rejects; I’ll correct it to valid forms (return x;andreturn x; print(...)) and verify genuine unreachable code remains reported with a non-semicolon code/location. - Assistant
The valid edge case behaves correctly: the separator-only function is absent, while
print(...)remains a finding with codeCalland line 5. Column fields are globally unavailable in the analyzer model and remain0-0for all findings, but the reported synthetic-semicolon symptom is eliminated as requested. I’ll now run the full Go test suite and inspect the final diff/status for unintended files or formatting issues. - Assistant
Verification is complete:
- Reproduced reported error: The original CLI run produced exactly two
unreachable_branchfindings withcode: ";". - Confirmed the fix: The same source now produces zero dead-code findings and
dead_blocks: 0. - Considered edge cases: A valid same-line case (
return x; print(...)) still reports the real unreachable call while excluding the separator; separator-only blocks are excluded from findings, counts, ratios, andHasDeadCode. - Ran affected tests:
go test ./internal/analyzerpasses. - Ran the full suite:
go test ./...passes across all packages. - Repository hygiene:
git diff --checkpasses, and onlyinternal/analyzer/dead_code.gois modified. No tests were added or changed, per instruction.
I’m satisfied the detector now filters synthetic semicolon nodes without altering CFG behavior or hiding genuine unreachable code, so I’ll submit the change.
- Reproduced reported error: The original CLI run produced exactly two
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.