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 locate the dead-code analyzer and its tests, then reproduce the reported behavior with the project’s own CLI or test harness. I’ll trace how unreachable CFG nodes are converted into findings, identify the AST/CFG representation of a trailing semicolon, and add the narrowest source fix without modifying repository tests. Finally I’ll run focused and broader relevant tests, inspect the diff, and verify the repro output no longer contains the empty-statement warning.
- Assistant
The repository is a Go implementation, with the likely logic in
internal/analyzer/dead_code.goand dedicated analyzer/app tests. I’ll inspect those files plus CFG node definitions and search forunreachable_branch,Empty, and semicolon/source extraction before running the focused tests. - Assistant
The detector currently filters only blocks with zero statements; it treats any non-empty block as actionable and emits one finding for the whole block. The parser has no explicit empty-statement node type, so I need to determine whether the semicolon is represented as a generic node or as an
Expr/token-derived node, and whether filtering should happen at block or individual-statement level. I’ll reproduce and inspect CFG/AST behavior directly. - Assistant
The initial reproduction is blocked by the environment: Go reports that neither
GOMODCACHEnorGOPATHis set, so dependencies cannot be resolved. I’ll inspect the project’s documented setup/Makefile and available Go environment, then configure a temporary cache or use the repository’s intended package manager without changing tracked files. - Assistant
The repro is confirmed: the CLI reports two dead-code issues and the generated report’s code is the bare semicolon. The focused analyzer tests pass baseline. Since
getNodeDescriptionfalls back tostring(node.Type)and produces;, the empty statement is represented by a parser node whose type is exactly";", notNodePass. I’ll inspect parser token handling and CFG construction to ensure the filter is robust and placed where metrics/findings both exclude semicolon-only blocks. - Assistant
The parser’s existing metrics code already identifies this exact representation with
string(node.Type) == ";"as a logical separator. I’ll reuse that semantic locally in dead-code reporting: exclude semicolon nodes when deciding whether an unreachable block is actionable, and ignore them when deriving code and line ranges. This handles semicolon-only blocks (no finding) and mixed blocks (only real statements are reported), while leaving explicitpassand all other unreachable statements unchanged. - Assistant
The source change now filters separator-only unreachable blocks before incrementing
DeadBlocksor creating findings, and excludes separators from mixed-block code/location extraction. It uses the repository’s existingisLogicalSeparatorhelper, so the representation is not duplicated. I’ll now rerun the CLI repro and focused tests, then run the full Go test suite to catch metric or API regressions. - Assistant
The fix resolves the repro: the report now has zero dead-code issues instead of two semicolon findings, and the health score reflects no dead code. Focused analyzer tests and the entire repository test suite pass. I’ll do a final diff/status review to ensure only the intended tracked source file changed and no generated artifacts are included, then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.