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 start by exploring the repository structure to understand the codebase and then reproduce the issue.
Assistant
This looks like a Go project with some Python components. Let me explore more to understand the structure.
Assistant
Let me look for files related to dead code analysis and the CFG/unreachable branch detection:
Assistant
Let me look at the dead code analyzer and the related files
Assistant
Now let me look at the reachability analyzer to understand how unreachable blocks are collected.
Assistant
Let me look at the reachability analyzer.
Assistant
Let me understand the node types and how empty statements are represented. Let me look at the parser.
Assistant
Let me do one command at a time.
Assistant
Let me look at the AST definition to understand the node types.
Assistant
Now let me look at how the CFG builder handles statements and which node types become empty. Let me also look at the
IsEmpty()method of BasicAssistant
Let me look at the CFG's
IsEmptymethod and also look at how blocks are built from the AST.Assistant
Let me look at how the CFG builder constructs blocks from
Assistant
Let me look at the CFG builder to understand how statements are processed
Assistant
Let me search for the
processStatementmethod which is central to how statements are processed.Assistant
Let me look at the
processStatementfunction and its handling of empty/expression statementsAssistant
Let me look at how the parser handles the
;separator and what the empty expression looks like.Assistant
Let me look at the AST builder to understand how expression_statements are handled.
Assistant
Let me find the
buildExpressionStatementfunction.Assistant
Let me see the
buildExpressionStatementfunction and its surroundings.Assistant
Let me look at the dead code service and formatter to understand how the "code" field gets the value
";".Assistant
Let me look at the dead code service to understand how findings are created and where the
codefield value";"comes from.Assistant
Let me first reproduce the issue. Let me create a test file and run the analysis
Assistant
Let me check if the tool is built and can be used:
Assistant
Let me build and run the tool.
Assistant
Let me set up the Go environment
Assistant
Let me set up the cache directories properly.
Assistant
Now let me run the analysis on the test file:
Assistant
Let me look at the JSON report to see the actual findings:
Assistant
I've confirmed the issue. The
codefield is";"with 0-0 column range. Let me see the full dead_code report.Assistant
Let me trace how the code
";"is generated. Let me search for where ";" is used:Assistant
Let me look at the raw_metrics.go and understand this node type
";":Assistant
Let me find where the
;node type is created:Assistant
Let me search more broadly for where this node type is created:
Assistant
Let me look at the AST builder to understand how nodes are built from tree-sitter:
Assistant
Let me look at the beginning of
buildNodeand thebuildExpressionStatementaround line 788:Assistant
Let me look at the rest of
buildNode, especially the default case:Assistant
Let me look at the end of
processStatementto see how the;node type is handled:Assistant
Let me see the rest of
processStatement:Assistant
Let me check if there's a constant for the semicolon node type and understand how it's used:
Assistant
Let me fix the command.
Assistant
Let me look at the
isLogicalSeparatorfunction inAssistant
Now I have a thorough understanding of the issue. Let me trace the root cause:
- When Python code has
raise ValueError("nope");, tree-sitter creates two nodes:raise_statementandexpression_statement. - The
expression_statementfor the trailing;has a child;token. - In
buildNode(), the;token doesn't match any case and falls to thedefault, creating a node with type";"(the raw tree-sitter type). - In
getNodeDescription()for the dead code report, it falls to thedefaultcase returningstring(node.Type)which is";". - The
;node ends up in an unreachable CFG block after return/raise. - The dead code detector reports it as a warning with
code: ";"and0-0column.
Now let me implement the fix. The best place is in
analyzeDeadBlockto filter out blocks containing only trivial/no-op statements like `;- When Python code has
Assistant
Let me open the file:
Assistant
Now I'll implement the fix. Let me modify the
analyzeDeadBlockfunction to skip blocks containing only trivial/no-op statements like semicolons:Assistant
Let me use the heredoc syntax for the edit command
Assistant
Now I need to add the
isTrivialBlockmethod. Let me find a good place for it:Assistant
Let me add the
isTrivialBlockmethod right afteranalyzeDeadBlock:Assistant
Now let me rebuild and test:
Assistant
Now let me test the fix with the repro script:
Assistant
Let me verify the JSON report:
Assistant
The fix works. Now let me make sure I haven't broken any existing tests. Let me also think about edge cases:
- What about code with a semicolon that has actual statements on both sides? E.g.,
return x; y = 1- the;node would be a separate statement, but the block would containreturn xtoo (in a different block), so it wouldn't be affected. Actually wait - after a return, the semicolon creates a new unreachable block. If there's also a real statement likey = 1after the semicolon, that would be in a separate block. Let me think...
Actually, the CFG builder processes each statement sequentially. For
return x;, the parser gives:return x(NodeReturn);(Node with type ";")
After processing the return,
currentBlockbecomes the unreachable block. Then the;gets added to the unreachable block. If there's alsoy = 1after the;, it would be in yet another statement that goes to a different unreachable block. So the fix correctly only filters blocks that consist entirely of;(or other trivial statements).Let me now run the existing tests.Now let me run the existing tests to ensure nothing is broken:
- What about code with a semicolon that has actual statements on both sides? E.g.,
Assistant
All dead code tests pass. Let me run the full test suite for the analyzer package and also the dead code service tests:
Assistant
All analyzer tests pass. Let me also run the service tests:
Assistant
Let me also think about
passstatements - they are also no-ops. Let me updateisTrivialStatementto also treatNodePassas trivial:Assistant
Let me rebuild and run all tests again:
Assistant
Let me run the full analyzer test suite again and also the service tests:
Assistant
All tests pass. Let me now also create a more comprehensive repro script to verify edge cases:
Assistant
Let me test with the edge case file:
Assistant
Let me fix the test file - the
;;may be causing a parse error:Assistant
Let me run the analysis again:
Assistant
Let me verify the JSON report to confirm only real dead code is reported:
Assistant
The fix is working correctly. Let me verify:
fandg(original repro): No findings - the semicolons are filtered ✅h(print("dead")): Correctly reported as critical dead code ✅j(return b;+print("also dead")): The block has both;and real code, so the real dead code is still reported ✅k(passafter return): Filtered out ✅
Let me review the final state of my changes:
Assistant
The diff looks clean. Let me also run the integration tests:
Assistant
Let me run all tests for the entire project:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.