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):pythondef f(x): if x is None: raise ValueError("nope"); return x def g(y): return y;Run:
bashpyscn analyze --json --no-open semi_repro.pyActual output
Two dead-code findings (from the generated JSON report):
json{"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 — a that points at literal with a column range reads as a real defect when there is none. Bounded impact: only fires on the rare trailing-semicolon style.
Assistant
Reproduced. Let's inspect the full finding for code/location fields.
Assistant
Confirmed. Now let's find where the block statements get the code text ";" - probably from source code substring using node positions where start==end. Let's inspect BasicBlock.Statements and getBlockCode, and how CFG builder adds statements for tree-sitter nodes.
Assistant
There's already a helper
raw_metrics.go:366checkingstring(node.Type) == ";". Let's look at it.Assistant
Good, there's precedent for this exact check. Now let's fix the dead_code.go analyzer to skip these logical separator nodes when building findings (both in analyzeDeadBlock filtering statements, and in getBlockStartLine/EndLine/getBlockCode should use filtered statements).
Assistant
That confirms it's likely a fallback that sets
NodeType(node.Kind())where kind literally is ";" from tree-sitter grammar. Now let's implement the fix in dead_code.go: filter statements that are logical separators when building findings (skip such statements entirely, and if a block is composed only of these, skip the whole block).Assistant
Same package. I can reuse
isLogicalSeparatordirectly in dead_code.go. Now let's modifyanalyzeDeadBlockto filter out statements that are only logical separators, and skip empty findings.Assistant
Now add the helper function
blockHasOnlyLogicalSeparators, and also updategetBlockCode,getBlockStartLine/getBlockEndLineto filter separator statements out just in case blocks have mixed content (some real statements plus a trailing;).Assistant
Now let's add a new helper function
blockHasOnlyLogicalSeparatorsnear these block-related helper functions.Assistant
Now also filter out logical separator statements when computing block code / start/end lines, for cases where a dead block has a mix of a real statement plus a trailing empty statement (so it doesn't misreport lines/code that include the semicolon). Let's check
getBlockCode,getBlockStartLine,getBlockEndLineagain to add filtering for a cleaner fix.Assistant
Now let's rebuild and rerun the repro.
Assistant
The findings are gone. Now let's verify real dead code cases still get detected (edge case: actual unreachable statements after return, not just semicolons).
Assistant
Real dead code with actual statements still gets detected properly (function h shows "Call\nCall" without the trailing
;polluting the code text). Now let's run the existing test suite for the analyzer package to make sure nothing broke.Assistant
All existing dead-code tests pass. Let's run the full analyzer test suite and also the service/domain tests to be thorough.
Assistant
All tests pass across the entire repository. Let's review the final diff.
Assistant
The diff is clean and minimal. Let's clean up temp files (not part of repo, so no need, but let's remove test scripts we created outside repo).
Assistant
Now let's go through the checklist explicitly.
Checklist review:
- Reproduced the error: Yes — I built the CLI, created
semi_repro.pyfrom the issue exactly, and confirmed the JSON report contained the boguscode: ";",unreachable_branch,warning-severity findings at0-0column for bothfandg. - Confirmed fix resolves the error: Yes — after the fix, rebuilding and re-running the same repro produced 0 dead-code findings and a 100/100 dead-code score, confirming the empty-statement false positives are gone.
- Thought about edge cases:
- Blocks that are entirely empty-statement blocks (the exact repro case) → filtered out entirely.
- Reproduced the error: Yes — I built the CLI, created
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.