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.
Assistant
Let me look more at the structure, particularly the internal directory and any code related to dead-code detection.
Assistant
Let me check the dead_code.go and dead_code_test.go files to understand the issue.
Assistant
Let me look at the parser to understand how empty statements are represented.
Assistant
Let me see all the NodeType definitions and look for empty statement-related types.
Assistant
Let me look at how the parser handles trailing semicolons (empty statements).
Assistant
Let me look at how the parser is implemented.
Assistant
Let me reproduce the issue first.
Assistant
Now let me reproduce the issue:
Assistant
Now let me understand how empty statements are represented in the parser.
Assistant
Let me look at the CFG builder to understand how empty statements are processed.
Assistant
Let me look at the
addStatementto see what happens with empty NodeExpr statements.Assistant
Let me look at how the empty statement gets into a basic block, by writing a debug script.
Assistant
Let me check how the location is being translated to JSON.
Assistant
Let me find where the conversion happens.
Assistant
Let me look at the reachability analyzer to understand what constitutes an unreachable block.
Assistant
Let me look at the BasicBlock definition.
Assistant
Let me look at the existing dead code tests.
Assistant
Now let me write a debug script to trace what happens in the CFG with these empty statements.
Assistant
Let me verify the type of the empty statement.
Assistant
Let me check the existing dead_code.go file for the structure and best place to apply the fix.
Assistant
Let me look at the CFG builder to understand how the empty statement is handled.
Assistant
OK so
NodeExpris added to the current block. The default case at the end of processStatement must add;as well.Assistant
Let me also check what happens with
passstatements.Assistant
So
passafter areturnis reported as critical (unreachable_after_return). That's a real finding because:passis an intentional Python statementpassshows up with proper code="pass"- It IS actually unreachable after a return
So
passis NOT the same issue as;. Thepassfinding is technically correct (though some might argue it's noise too).Now let me focus on the fix for the
;issue.Let me also check what happens with multiple statements in a block (like
; ;):Assistant
Let me try with different syntax.
Assistant
The Python parser doesn't accept
pass;after a return becausepassends the block. Let me try somethingelse.Assistant
So I need a filter that only skips blocks where ALL statements are empty. Let me verify with another scenario.
Assistant
Let me check the
if False: ;case.Assistant
Let me also test a standalone
;and multiple;cases.Assistant
Now I have a clear understanding of the issue. Let me plan and implement the fix.
Plan:
- Add a helper function
isEmptyStatement(stmt *parser.Node) boolthat detects empty statement nodes (Type";"). - Add a helper function
blockContainsOnlyEmptyStatements(block *BasicBlock) boolto check if a block contains only empty statements. - In
Detect(), filter out blocks that contain only empty statements before processing them. - Update
DeadBlockscount to reflect filtered count.
Let me also look at the existing tests to make sure I understand the structure properly:
- Add a helper function
Assistant
Now let me implement the fix:
Assistant
Now let me implement the fix:
Assistant
Now let me apply the fix:
Assistant
Let me apply the fix using the edit command.
Assistant
Now let me add the helper functions. Let me look at the file structure first:
Assistant
Now let me add the helper functions after the
DetectInFilefunction (around line 192):Assistant
Now let me add the helper functions after the
DetectInFilefunction:Assistant
I see there's some duplication. Let me fix the file:
Assistant
Let me fix the duplicate comment lines:
Assistant
Let me fix the duplicate lines:
Assistant
Let me revert the file and re-apply changes more cleanly:
Assistant
Now let me apply the changes one at a time, more carefully.
Assistant
Now let me apply the change to Detect() first:
Assistant
Now let me add the helper functions between
DetectInFileandanalyzeDeadBlock:Assistant
Let me verify the full file structure looks good:
Assistant
Now let me build the code to check for errors:
Assistant
Good, the build succeeds. Now let me run the existing dead_code tests to make sure nothing is broken:
Assistant
All existing dead code tests pass. Now let me build and verify the fix works with the repro case:
Assistant
The fix works for the empty
;case. Let me also verify with the multi-case:Assistant
The fix is working as expected. Now let me run the full test suite to make sure nothing else is broken:
Assistant
All tests in the analyzer package pass. Let me also run the broader test suite to make sure nothing else is affected:
Assistant
All tests pass. Let me now also write a test case to verify the new behavior. First let me check the existing test file structure:
Assistant
Let me create a temporary test script to verify the fix:
Assistant
All test cases pass. Let me now verify with the exact reproduction script from the issue:
Assistant
The fix is working perfectly. Let me also verify mixed cases more thoroughly:
Assistant
Let me also run the complete test suite once more to confirm everything works:
Assistant
Let me view the full updated dead_code.go to verify everything looks clean:
Assistant
Now let me verify with the actual bioconvert examples to be thorough:
Assistant
Let me also do a more thorough verification:
Assistant
Hmm, the parser failed to parse due to syntax errors. The
;on its own line is not valid Python. Let me adjust the test:Assistant
All test cases work correctly:
- test1 (
return 42;): No finding - filtered out (empty;) - test2 (
raise ValueError("err");): No finding - filtered out (empty;) - test3 (
return 1; x = 2;): Finding reported with realassignmentcode (mixed case) - test4 (
return 1; x = 2): Finding reported normally - test6 (
return 1; pass): Finding reported withcode='pass'(intentional code) - test7.inner: Finding reported normally
Let me now look at the final file once more to verify everything is clean:
- test1 (
Assistant
Let me check git status to confirm only the intended file is modified:
Assistant
Let me clean up the temporary test files:
Assistant
Let me also run the test suite one more time to confirm everything still works:
Assistant
All tests pass. Let me also run the full test suite once more:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.