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 and find the dead-code analyzer.
Assistant
This is a Go project (go.mod, cmd, internal, etc.) with some Python test data. Let me explore the structure.
Assistant
Let me look at the CFG builder and the parser to understand how empty statements are represented.
Assistant
Let me reproduce the issue first.
Assistant
I've reproduced the issue. The finding has
code: ";"with0-0columns. Now let me understand how the empty statement node is created. Let me look at the CFG builder and how the empty statement is parsed.Assistant
The empty statement produces a
NodeExprwith no children. But the JSON showscode: ";", not "expression". Let me look at the service layer that builds the final report.Assistant
The JSON shows
code: ";"butgetBlockCodewould return "expression". Let me check if there's another code path in the app/usecase layer.Assistant
Let me check where
;comes from - maybegetBlockCodeuses source text. Let me write a debug script to inspect the CFG.Assistant
Let me actually look at how the report is generated. Maybe the
codefield is generated from source text in a presentation layer. Let me search for where code might be set to the source text snippet.Actually, let me just trace. The finding in the JSON has
"code": ";". Let me check the DeadCodeFinding domain struct and whether code gets overridden by a presentation layer that reads source lines.Let me search more broadly for where code is set to source line text.
Assistant
Hmm, no source-line code generation. So where does ";" come from? Let me re-examine. Maybe
getNodeDescriptiondoesn't actually handle this node type, and the node's Type is something that returnsstring(node.Type). Let me check what node type the empty statement gets. Maybe it's notNodeExpr.Actually wait, let me re-read
buildExpressionStatement. If the expression_statement has no non-trivia children, it returnsNewNode(NodeExpr)with location = location of the expression_statement node. So node type is NodeExpr. ThengetNodeDescriptionreturns "expression".But the output is ";". So either the code field is set elsewhere, OR there's a different path. Let me actually run a debug. Let me write a small Go test or use the existing tests to print.
Actually, let me check the JSON finding again - maybe the field "code" maps to something else. Let me check the domain.DeadCodeFinding struct and its JSON tags.
Assistant
Let me write a debug test to inspect the CFG blocks and statements for the repro.
Assistant
The empty statement node has type
";"(literal). Let me find where this node type is created.Assistant
There's already a helper
isLogicalSeparator. Let me find where the;node is created in the parser.Assistant
The
;node is created via the default case inbuildNode. Now let me look at the reachability analyzer to understandGetUnreachableBlocksWithStatements.Assistant
Let me check
BasicBlock.IsEmpty().Assistant
Now let me look at existing tests to make sure I understand what's tested and don't break things.
Assistant
Let me look at the dead_code_test.go to understand existing test patterns and check for pass/unreachable tests.
Assistant
There's a test case at lines 125-140 that involves
passafterunreachable = True. Let me look at it.Assistant
Let me check the
DeadCodeLocationstruct for the column fields shown in JSON.Assistant
Let me look at
isLogicalSeparatorand the parser NodeType to design the helper.Assistant
Now I'll implement the fix. Let me first check existing tests that assert on the
codefield to avoid breaking them.Assistant
Let me check how
expectedDeadis computed in the test to ensure my changes don't break counts.Assistant
Let me look at
TestDeadCodeWithStatementsandTestDeadCodeEdgeCasesto ensure no empty-only blocks.Assistant
Let me check cfg.go's imports and structure.
Assistant
Now let me add the helper methods to cfg.go, right after
IsEmpty():Assistant
Now update reachability.go to exclude blocks with only empty statements.
Assistant
Let me add a convenience method and update the reachability methods.
Assistant
Now let me also add a safety net in
analyzeDeadBlockto skip empty-only blocks, and filter empty;statements fromgetBlockCodeso mixed blocks don't show the bare;:Assistant
Now let me update
getBlockCodeto skip empty;statements in mixed blocks:Assistant
Let me rebuild and run the debug test plus the actual CLI repro.
Assistant
Dead Code now shows "0 issues". Let me verify the JSON report has no findings.
Assistant
The fix works—0 findings. Now let me test edge cases to ensure real dead code is still detected, and mixed cases with
;followed by real dead code.Assistant
Edge cases work correctly:
f/g(trailing;only): no findings ✓real_dead: reported ✓mixed(return a; q = 1): the realq = 1is reported, the bare;is filtered from code ✓normal_semi: no findings ✓
Now let me run the full analyzer and service test suites to ensure nothing breaks.
Assistant
All tests pass. The instructions say not to add tests to the repository, so let me remove my debug test file.
Assistant
Let me check how
isLogicalSeparatoris used to see if refactoring it to use the new helper is safe.Assistant
I'll leave
isLogicalSeparatorin raw_metrics.go independent (it's a separate LLOC concern) to avoid unintended coupling. Let me review the final diff.Assistant
Let me run gofmt to ensure formatting is correct.
Assistant
Let me run the analyzer tests once more to confirm everything passes after gofmt.
Assistant
Let me do a final verification with the original repro from the issue.
Assistant
The issue is resolved. Let me clean up the generated report artifacts.
Assistant
The fix is complete. Let me review the final diff one last time before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.