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
Let me start by understanding the repository structure and then reproduce the issue.
Assistant
This looks like a Go project (based on go.mod) with a Python component (pyproject.toml). The tool is "pyscn" - a Python scanner. Let me explore the structure more.
Assistant
Let me run a single command at a time.
Assistant
The issue mentions dead-code detector. Let me look at the analyzer directory - that likely has the dead-code detection logic.
Assistant
Let me first create the reproduction script and look at the dead code analyzer:
Assistant
Now let's try to run the tool. But first I need to find the executable.
Assistant
No pre-built binary. Let me check the Makefile and Go module to understand how to build.
Assistant
Let me build the binary first
Assistant
Let me set up the Go environment.
Assistant
Need GOCACHE as well.
Assistant
Now let's reproduce the issue by running the tool on the test file:
Assistant
Now let me check the generated JSON report to see the dead code findings:
Assistant
I've confirmed the issue. Now let me look at the
dead_code.gofile to understand how dead code findings are generated and where I need to filter out empty statements.Assistant
The
opencommand is a special command, not a direct file access. Let me try again.Assistant
Let me continue reading the file to understand the logic, especially how findings are generated for unreachable branches.
Assistant
Let me continue reading to understand how code is extracted for
Assistant
Let me look at
getBlockCodeand relevant helper functions:Assistant
The file is open, let me search within the currently open file.
Assistant
Let me go to line 411 to see getBlockCode.
Assistant
Now I see the issue. In
getNodeDescription, thedefaultcase returnsstring(node.Type). Let me check the parser's node types to understand what type an empty statement would have:Assistant
Let me look at the AST definitions to see what node types exist.
Assistant
Let me look at the reachability analyzer to understand
GetUnreachableBlocksWithStatements.Assistant
Let me search for
GetUnreachableBlocksWithStatements.Assistant
Let me look at the
GetUnreachableBlocksWithStatementsfunction.Assistant
Let me check the
IsEmptymethod onBasicBlockin the CFG definition.Assistant
Let me look at the BasicBlock struct and its IsEmpty method.
Assistant
Let me look at the IsEmpty method of BasicBlock.
Assistant
Let me look at the CFG builder to understand how empty statements are
Assistant
Let me check how the parser handles empty statements (semicolons). Let me look at the tree-sitter AST and how it maps nodes
Assistant
Let me look at the context around line 108 in ast_builder.go.
Assistant
Let me find the
buildExpressionStatementfunction.Assistant
Let me look at that function.
Assistant
Let me look at the
isTriviafunction to understand how it handles the semicolon.Assistant
Let me look at that function.
Assistant
Let me look at the main dispatch function in ast_builder.go to understand what happens when an unknown node type is
Assistant
Let me continue reading to find the default
Assistant
Let me search for any existing tests or code related to semicolons in the dead code analyzer
Assistant
Let me look at the dead_code_test.go file to understand the test
Assistant
Let me write a quick test to see what node type the parser assigns to
;. First let me check if I can trace the issue more precisely.Assistant
Let me create a temporary test file within the analyzer package to understand the node types.
Assistant
Let me check the correct function names in the parser package.
Assistant
Let me check the CFG builder function.
Assistant
Let me look at how existing tests create CFGs.
Assistant
Let me look at how the tests build CFGs from source code.
Assistant
Let me fix the debug test and run it.
Assistant
Now I can see the issue clearly. The
";"node is a statement with type";"and valid location. Let me look at how the reporter formats findings to understand the column issue.Assistant
Let me find where the dead code findings are serialized.
Assistant
Let me search for the JSON reporting structure.
Assistant
Let me look at the domain dead_code.go to understand the JSON serialization.
Assistant
Let me find where the conversion from analyzer to domain happens.
Assistant
Let me look at how findings are converted in dead_code_service.go.
Assistant
Let me look at the dead_code_service.go file for the conversion from analyzer to domain findings.
Assistant
Now I have a clear understanding of the issue. Let me implement the fix. The approach is to modify
analyzeDeadBlockindead_code.goto skip blocks that only contain semantically empty statements (bare;separators andpassstatements).Let me first clean up my debug test file, then implement the fix.
Assistant
Now let me implement the fix. Let me read the
analyzeDeadBlockfunction in the currently open file.Assistant
Now I'll implement the fix. Let me edit
analyzeDeadBlockto add a check for empty statementsAssistant
Good, now let me add the helper functions at the end of the file.
Assistant
Now let me add the helper functions at the end of the file.
Assistant
Now let me rebuild and test the fix.
Assistant
Good, it compiles. Now let's test the reproduction case.
Assistant
The dead code score is now 100/100 with 0 issues! Let me verify the JSON report.
Assistant
The fix works. Now let me verify that legitimate dead code is still detected.
Assistant
Legitimate dead code is still detected (2 issues, 2 critical). Let me verify the JSON details.
Assistant
Let me also test an edge case - what about
passafter return?Assistant
Both cases are properly filtered. Now let me run the existing unit tests to make sure nothing is broken.
Assistant
All dead code tests pass. Let me also run the full test suite and the reachability tests.
Assistant
All tests pass. Let me also run the full test suite to be safe.
Assistant
All tests pass across the entire project. Let me also verify with a more complex edge case - a semicolon in a more realistic code scenario.
Assistant
There's a syntax error. Let me fix the test case - bare
;on a line is invalid Python.Assistant
Let me check the detailed findings for edge cases.
Assistant
The main fix works well. But I noticed that in the
f6case (return d; x = d + 1), the code field includes";\nassignment"which is not ideal. Let me also improvegetBlockCodeto skip empty statements in the code representation.Assistant
Let me improve
getBlockCodeto skip empty statements from the code representation.Assistant
Now let me rebuild and retest.
Assistant
Let me check the detailed findings now.
Assistant
The code field is now clean. Let me run the original reproduction case again and run all tests one more time.
Assistant
The original case now shows 0 dead code issues. Let me run the full tests one final time.
Assistant
All tests pass. Let me verify the final state of the changes I made.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.