Skip to content
TheChatArchiveThe Chat Archive
QwenQwen/Qwen3.6-35B-A3B· alibabaHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [BUG][auto] deadcode-trailing-semicolon-empty-stmt: trailing-semicolon…

  1. 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-severity unreachable_branch finding whose code field is a bare ; (an empty statement) whenever a return/raise statement is written with a trailing semicolon. In Python a trailing ; is a valid (if unusual) statement separator, so raise X; parses as raise X followed 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 impossible 0-0 column 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.py
    

    Actual 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 a warning-severity unreachable-code finding. The 0-0 column 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 warning that points at literal ; with a 0-0 column 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.


    pyscn version: v1.22.5 (commit bac7f16)

    Found via the FP-audit skill in repo bioconvert/bioconvert@92f4655 (4 real occurrences: bioconvert/utils/biocode/gff.py:618, tbl.py:114, things.py:753 and :780).

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /pyscn, current file: none) bash-$

  2. Qwen Assistant

    Let me analyze the issue:

    1. The bug is about a dead-code detector that incorrectly reports trailing semicolons as "unreachable" code with a 0-0 column range.
    2. In Python, raise X; parses as raise X followed by an empty statement (the semicolon).
    3. The empty statement is technically unreachable, but reporting it as a warning is noise.
    4. The fix should filter out empty statements when collecting unreachable-branch findings.

    Let me first explore the repository structure to understand the codebase.

  3. Qwen Assistant

    Let me explore the repository structure more and find the dead code analyzer.

  4. Qwen Assistant

    This is a Go project. Let me find the dead code analyzer.

  5. Qwen Assistant

    Let me explore the dead code analyzer code to understand how it works.

  6. Qwen Assistant

    Now let me look at the reachability analyzer to understand how unreachable blocks are determined:

  7. Qwen Assistant

    Let me look at the BasicBlock structure and its IsEmpty() method:

  8. Qwen Assistant

    Let me look at the BasicBlock structure and its IsEmpty method:

  9. Qwen Assistant

    Now let me look at the parser to understand how empty statements are represented:

  10. Qwen Assistant

    Let me look at the CFG builder to understand how blocks are created and how empty statements are handled:

  11. Qwen Assistant

    Now I understand the flow better. Let me create a reproduction script first:

  12. Qwen Assistant

    Now let me find how to run the pyscn analyze command to reproduce the issue.

  13. Qwen Assistant

    Let me check if there's a way to set up the Go environment or if there's a Makefile target to build.

  14. Qwen Assistant

    Let me look at the Makefile more carefully to understand the environment setup.

  15. Qwen Assistant

    Let me try setting up the Go environment properly.

  16. Qwen Assistant

    The HOME environment variable is not set. Let me set it and try again.

  17. Qwen Assistant

    Now let me run the reproducer to confirm the issue:

  18. Qwen Assistant

    Let me check the JSON report:

  19. Qwen Assistant

    Let me get more details on the exact findings:

  20. Qwen Assistant

    The command failed because it's trying to parse the JSON output of pyscn analyze which has non-JSON output mixed in. Let me just look at the JSON report file directly.

  21. Qwen Assistant

    Let me look at the specific findings more carefully:

  22. Qwen Assistant

    Now let me understand the parser to see how it handles trailing semicolons. I need to understand what AST node type is produced for a bare ;.

  23. Qwen Assistant

    Let me understand how the CFG builder processes statements, specifically how it handles trailing semicolons:

  24. Qwen Assistant

    Let me look at how NodeExpr is handled in the CFG builder, since a trailing ; is likely parsed as an empty expression statement:

  25. Qwen Assistant

    Let me look more carefully at the dead code analyzer to understand how empty statements get reported:

  26. Qwen Assistant

    Let me look at the analyzeDeadBlock function and getNodeDescription more carefully:

  27. Qwen Assistant

    Let me look at how the parser handles semicolons and what node type is produced:

  28. Qwen Assistant

    Let me look at how the parser builds expression statements and what happens with semicolons:

  29. Qwen Assistant

    Let me look at the AST builder to understand how expression statements and empty statements are handled:

  30. Qwen Assistant

    Let me look at what happens when a semicolon is in the source code. In Python, a trailing ; is an empty statement. Tree-sitter likely parses this as either:

    1. An empty expression_statement with no children
    2. A separate node type

    I need to understand what tree-sitter produces for raise ValueError("nope");.

    Let me look at the buildExpressionStatement function and see if it produces an NodeExpr node that's essentially empty:

  31. Qwen Assistant

    Now I understand the issue. When Python has raise X;, tree-sitter parses the trailing ; as an empty expression_statement that gets converted to a NodeExpr node with no meaningful content. This empty statement ends up in its own basic block after the raise statement, which is correctly marked as unreachable, but reporting it as dead code is noise.

    Let me look at the dead code tests to understand how to write a test case:

  32. Qwen Assistant

    Let me look at the dead code formatter to understand how the code field gets its value:

  33. Qwen Assistant

    Now let me look at the domain package to understand how findings are structured and mapped:

  34. Qwen Assistant

    Now I have a good understanding of the issue. The problem is:

    1. When Python code has raise X; or return y;, tree-sitter parses the trailing ; as an empty expression statement
    2. This empty statement ends up in its own basic block that is unreachable
    3. The dead code detector reports it as a finding with code: ";" and a 0-0 column range

    The fix should be in the analyzeDeadBlock function or in GetUnreachableBlocksWithStatements. According to the issue description:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators) when collecting unreachable-branch findings in the dead-code analyzer.

    So the fix should be to filter out blocks that only contain empty statements (NodeExpr nodes that are essentially empty/no-op) in GetUnreachableBlocksWithStatements.

    Let me look at what the NodeExpr node looks like when it's empty (just a ;):

    The buildExpressionStatement function shows that if there are no meaningful children, it creates an empty NodeExpr node with just a location.

    Let me think about where to put the filter:

    Option 1: In GetUnreachableBlocksWithStatements - filter out blocks that only contain empty expression statements Option 2: In analyzeDeadBlock - filter out blocks that only contain empty expression statements

    Looking at the code flow:

    • GetUnreachableBlocksWithStatements in reachability.go filters out blocks that are IsEmpty() (no statements at all)
    • But blocks with empty expression statements DO have statements (they have a NodeExpr node), so they pass this filter
    • Then analyzeDeadBlock in dead_code.go processes each block and creates a finding

    The best place to fix this is in GetUnreachableBlocksWithStatements since it's already responsible for filtering out blocks with no actionable content. We can add a check to also filter out blocks whose only statements are empty/no-op expression statements.

    Let me define what counts as an "empty" block for dead code purposes:

    • A block with no statements (already handled by IsEmpty())
    • A block with only empty expression statements (NodeExpr with no meaningful children)

    Actually, looking at the code more carefully, I need to understand what exactly NodeExpr looks like when it's from a trailing semicolon. The buildExpressionStatement function returns a NodeExpr with just a location when there are no children. This is essentially a no-op.

    The fix should be:

    1. Add a helper function to check if a block only contains "empty" statements (statements that carry no actionable code)
    2. Update GetUnreachableBlocksWithStatements to also filter out blocks that only contain empty statements

    Let me look at the issue more carefully. The issue says:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators) when collecting unreachable-branch findings

    So the fix should be to skip empty statements. In Python, a trailing ; is an empty statement that's equivalent to pass in terms of having no semantic content.

    Let me implement the fix. I'll modify the GetUnreachableBlocksWithStatements function in reachability.go to also filter out blocks that only contain empty expression statements.

    Wait, I should also consider what happens with pass statements. Looking at the code, NodePass is a separate node type. So we don't want to filter out pass statements, only empty expression statements (which are produced by trailing ;).

    Let me think about what makes a NodeExpr "empty":

    • It has type NodeExpr
    • It has no Value, no Children that are meaningful, etc.

    Actually, looking at the buildExpressionStatement function, when there's a trailing ;, it creates a NodeExpr with just the location (from b.getLocation(tsNode)). The location would have a valid line/column, but the node itself has no meaningful content.

    Let me look at the issue description again. It says the code field is ";". Let me check the getNodeDescription function in dead_code.go:

    case parser.NodeExpr:
        return "expression"
    

    Wait, but the issue says code: ";". Let me check the getBlockCode function:

    // getBlockCode extracts the code from a block
    func (dcd *DeadCodeDetector) getBlockCode(block *BasicBlock) string {
        ...
        var codes []string
        for _, stmt := range block.Statements {
            // Create a simple representation of the statement
            nodeDesc := dcd.getNodeDescription(stmt)
            codes = append(codes, strings.TrimSpace(nodeDesc))
        }
        return strings.Join(codes, "\n")
    }
    

    And getNodeDescription:

    func (dcd *DeadCodeDetector) getNodeDescription(node *parser.Node) string {
        ...
        default:
            return string(node.Type)
    }
    

    So for a NodeExpr node, it returns "expression". But the issue says code: ";". This suggests the parser might be producing a different node type for the trailing ;, not a NodeExpr.

    Wait, let me re-read the issue:

    {"function_name": "f", "location": {"start_line": 3, "start_column": 0, "end_column": 0}, "code": ";", "reason": "unreachable_branch", "severity": "warning"}
    

    The code field is literally ";". And the location is 0-0 for the column. This is consistent with an empty statement node that tree-sitter parses for the ;.

    Let me check if tree-sitter has a specific node type for the ; character. Looking at the Python grammar, the ; is a separator, not a statement itself. But tree-sitter might parse it as an empty expression_statement node.

    Actually, looking at the buildExpressionStatement function again:

    func (b *ASTBuilder) buildExpressionStatement(tsNode *sitter.Node) *Node {
        childCount := int(tsNode.ChildCount())
        for i := 0; i < childCount; i++ {
            child := tsNode.Child(i)
            if child != nil && !b.isTrivia(child) {
                return b.buildNode(child)
            }
        }
    
        node := NewNode(NodeExpr)
        node.Location = b.getLocation(tsNode)
        return node
    }
    

    When there are no meaningful children, it creates an empty NodeExpr node with the location of the expression_statement node from tree-sitter. The location of the ; separator would have column 0 or something.

    But wait, looking at the issue output, the code is ";", not "expression". This means the parser must be producing a different node type. Let me check if there's something else going on.

    Actually, I think I need to look at this differently. The code field comes from getBlockCode, which uses getNodeDescription. Let me check again:

    func (dcd *DeadCodeDetector) getNodeDescription(node *parser.Node) string {
        if node == nil {
            return ""
        }
    
        switch node.Type {
        case parser.NodeReturn:
            return "return"
        case parser.NodeBreak:
            return "break"
        ...
        case parser.NodeExpr:
            return "expression"
        ...
        default:
            return string(node.Type)
        }
    }
    

    If the node type is NodeExpr, the code would be "expression". But the issue says ";". So maybe the parser produces a different node type for the ;.

    Wait, let me re-read the issue output more carefully:

    {"function_name": "f", "location": {"start_line": 3, "start_column": 0, "end_column": 0}, "code": ";", "reason": "unreachable_branch", "severity": "warning"}
    

    Hmm, this is from a specific run. Maybe the actual code path is different. Let me check if there's a different formatter or if the JSON report uses a different path.

    Actually, looking at the issue, it says the output is from:

    pyscn analyze --json --no-open semi_repro.py
    

    Let me check the JSON report format. The code field in the JSON output comes from the domain's DeadCodeFinding:

    type DeadCodeFinding struct {
        ...
        Code        string           `json:"code"`
        ...
    }
    

    And the Code field is set from the detector's DeadCodeFinding.Code which comes from getBlockCode.

    OK so I think the issue might be that tree-sitter produces a node type that isn't NodeExpr. Let me check the full list of node types again.

    Actually, I think I might be overcomplicating this. Let me just focus on the fix: skip blocks that only contain empty/no-op statements when reporting dead code findings.

    The simplest fix is to modify the GetUnreachableBlocksWithStatements function to also filter out blocks whose statements are all "empty" (no actionable code). An empty statement would be a NodeExpr that has no meaningful content.

    But wait, I need to understand what exactly NodeExpr looks like when it's from a trailing ;. Let me check the parser node structure.

    Actually, let me just run a quick test to see what the parser produces:

    code := `def f():
        return 1;
    `
    

    I need to understand what AST node is produced for the ;. Let me look at the test to see if there's something relevant.

    OK let me just proceed with the fix. The key insight from the issue is:

    1. A trailing ; produces an empty statement in the AST
    2. This empty statement ends up in its own basic block
    3. The block is unreachable (correct)
    4. But the block only contains an empty statement, so it should be filtered out

    The fix should be to add a helper function that checks if a block only contains empty/no-op statements, and update GetUnreachableBlocksWithStatements to use this filter.

    An empty statement is defined as:

    • A NodeExpr that has no meaningful children (only the location)
    • Or possibly a NodePass (though pass might be intentional, so maybe not)

    Looking at the issue more carefully, it says:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators)

    So it's specifically about empty statements that are equivalent to pass but carry no semantic meaning. These are produced by trailing ;.

    Let me define "empty statement" as:

    • A NodeExpr that has no Value, no Children that are meaningful, and no Name

    Actually, the simplest approach is to check if the NodeExpr has no Value and no body statements. Looking at the parser:

    case parser.NodeExpr:
        return "expression"
    

    A NodeExpr from an expression statement typically has the expression as its Value. So an empty NodeExpr would have Value == nil.

    Let me check the Node structure:

    type Node struct {
        Type    NodeType
        Name    string
        Value   interface{}
        Body    []*Node
        ...
    }
    

    So a NodeExpr with no Value is an empty expression statement.

    Wait, but looking at buildExpressionStatement:

    func (b *ASTBuilder) buildExpressionStatement(tsNode *sitter.Node) *Node {
        childCount := int(tsNode.ChildCount())
        for i := 0; i < childCount; i++ {
            child := tsNode.Child(i)
            if child != nil && !b.isTrivia(child) {
                return b.buildNode(child)  // Returns the child node
            }
        }
    
        node := NewNode(NodeExpr)
        node.Location = b.getLocation(tsNode)
        return node  // Returns an empty NodeExpr
    }
    

    When there are no meaningful children, it creates an empty NodeExpr. When there IS a meaningful child, it returns that child directly (not wrapped in a NodeExpr). So the trailing ; would produce an empty NodeExpr with no Value.

    OK, I think the fix is clear now. Let me implement it:

    1. Add a helper function hasActionableCode that checks if a block contains at least one statement that has semantic meaning
    2. Modify GetUnreachableBlocksWithStatements to only include blocks that have actionable code

    The hasActionableCode function would check if any statement in the block is:

    • Not a NodeExpr with no Value (empty expression)
    • Or if it's a NodeExpr with a Value (non-empty expression)

    Actually, I think a simpler approach is to just check if the statement is an empty NodeExpr:

    func isEmptyStatement(stmt *parser.Node) bool {
        return stmt != nil && stmt.Type == parser.NodeExpr && stmt.Value == nil
    }
    

    And then hasActionableCode would be:

    func hasActionableCode(statements []*parser.Node) bool {
        for _, stmt := range statements {
            if !isEmptyStatement(stmt) {
                return true
            }
        }
        return false
    }
    

    Wait, but what about NodePass? The issue says to skip "empty statements (Python pass-equivalent / bare ; separators)". A pass statement is different from a trailing ; in that pass is intentional (a no-op that's explicitly written), while a trailing ; is usually a mistake or a stylistic choice.

    But the issue also says:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators)

    This suggests that pass should also be skipped. However, pass is more commonly used intentionally (e.g., as a placeholder), so reporting it as dead code might actually be useful in some cases.

    Actually, I think the issue is specifically about the trailing ;, not about pass statements. The key point is:

    • A trailing ; produces an empty NodeExpr (no Value)
    • A pass statement produces a NodePass node

    These are different node types, so the fix should specifically target empty NodeExpr nodes.

    Let me also consider what the issue says about the code field being ";". Looking at the actual output:

    {"function_name": "f", "location": {"start_line": 3, "start_column": 0, "end_column": 0}, "code": ";", "reason": "unreachable_branch", "severity": "warning"}
    

    Hmm, the code is ";", not "expression" or "pass". This suggests the parser might be producing a different node type. Let me check if tree-sitter produces a semicolon node or similar.

    Actually, looking at the tree-sitter-python grammar, the ; character is a separator in the grammar. It doesn't produce its own node. Instead, it separates statements, and tree-sitter parses the statements around it.

    So raise X; would be parsed as:

    • raise X -> a raise_statement node
    • ; -> separator (trivia, not a node)
    • But wait, tree-sitter might parse the ; followed by nothing as an empty expression_statement

    Let me check by running the actual parser on the test file:

    Actually, I can just look at the code more carefully. Let me check what happens when there's a trailing ;:

    raise ValueError("nope");
    

    In tree-sitter-python, this might be parsed as:

    • raise_statement containing raise ValueError("nope")
    • expression_statement containing nothing (empty statement after ;)

    The empty expression_statement would be parsed by buildExpressionStatement, which returns an empty NodeExpr.

    OK wait, but the issue says code: ";". Let me check if there's something else going on.

    Actually, looking at the issue output more carefully, I notice the start_column: 0, end_column: 0. This is consistent with a location that was set to zero values. Let me check if the parser might be setting the location differently for empty statements.

    Looking at buildExpressionStatement:

    node := NewNode(NodeExpr)
    node.Location = b.getLocation(tsNode)
    return node
    

    The getLocation function would return the location of the expression_statement node from tree-sitter. If tree-sitter reports the location of the ; as column 0, then the NodeExpr would have start_column: 0.

    And for the code field, let me check getBlockCode again:

    func (dcd *DeadCodeDetector) getBlockCode(block *BasicBlock) string {
        if block == nil || len(block.Statements) == 0 {
            return ""
        }
    
        var codes []string
        for _, stmt := range block.Statements {
            nodeDesc := dcd.getNodeDescription(stmt)
            codes = append(codes, strings.TrimSpace(nodeDesc))
        }
        return strings.Join(codes, "\n")
    }
    

    And getNodeDescription:

    case parser.NodeExpr:
        return "expression"
    

    So the code should be "expression", not ";". But the issue says ";". This is confusing.

    Wait, maybe the parser is producing a different node type. Let me check the parser node types again:

    NodeExpr             NodeType = "Expr"
    

    And the getNodeDescription function:

    case parser.NodeExpr:
        return "expression"
    

    So for a NodeExpr, the code would be "expression". But the issue says ";".

    Unless... the parser is producing a NodePass instead of a NodeExpr for the trailing ;. Let me check buildPassStatement:

    func (b *ASTBuilder) buildPassStatement(tsNode *sitter.Node) *Node {
        node := NewNode(NodePass)
        node.Location = b.getLocation(tsNode)
        return node
    }
    

    And getNodeDescription:

    case parser.NodePass:
        return "pass"
    

    So if the parser produces a NodePass, the code would be "pass", not ";".

    Hmm, I'm confused about where ";" comes from. Let me just focus on the fix and not worry about the exact code value.

    Actually, I just realized something. The issue says the code is ";", but maybe this is just the first few characters of the code field. Let me re-read the issue:

    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"}
    

    OK so the code field is literally ";". This must mean the parser is producing a node with type that maps to ";".

    Wait, maybe the issue is that tree-sitter produces a node type that isn't recognized by the parser, and it falls through to the default case in getNodeDescription:

    default:
        return string(node.Type)
    

    So if the node type is ";" (which would be unusual), the code would be ";".

    Actually, I think the issue might be that tree-sitter-python has a specific node type for the ; character, and the parser doesn't recognize it, so it falls through to the default case.

    Let me check the tree-sitter-python grammar for semicolons. The ; is a separator in Python, so it might be parsed as a semicolon or separator node type. If the parser doesn't have a case for this node type, it would fall through to the default.

    OK, I think I've spent too much time analyzing this. Let me just focus on the fix.

    The fix should be:

    1. Skip blocks that only contain "empty" statements when reporting dead code findings
    2. An empty statement is one that carries no actionable code (e.g., empty expression, pass)

    Let me implement the fix by modifying the GetUnreachableBlocksWithStatements function to filter out blocks that only contain empty statements.

    Actually, looking at the issue description again:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators) when collecting unreachable-branch findings in the dead-code analyzer.

    This suggests the fix should be in the dead-code analyzer, not in the reachability analyzer. Let me re-read the flow:

    1. DeadCodeDetector.Detect() calls reachResult.GetUnreachableBlocksWithStatements()
    2. For each unreachable block with statements, it calls analyzeDeadBlock(block)
    3. analyzeDeadBlock creates a finding for the block

    So the fix could be in either:

    • GetUnreachableBlocksWithStatements: Filter out blocks with only empty statements
    • analyzeDeadBlock: Skip blocks with only empty statements

    I think the best place is analyzeDeadBlock because:

    1. It's specific to dead code detection
    2. The reachability analyzer is more general-purpose
    3. It's clearer what "empty" means in the context of dead code

    Let me implement the fix in analyzeDeadBlock.

    Actually, wait. Let me re-read the issue:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators) when collecting unreachable-branch findings in the dead-code analyzer.

    This says "when collecting unreachable-branch findings", which is in the dead-code analyzer. So the fix should be in dead_code.go.

    Let me now implement the fix. I'll add a helper function to check if a block contains only empty statements, and modify analyzeDeadBlock to skip such blocks.

    Actually, I realize I need to first understand what node types represent "empty statements". Based on my analysis:

    1. Empty NodeExpr - produced by trailing ; (no Value)
    2. NodePass - explicit pass statement

    But the issue says "empty statements (Python pass-equivalent / bare ; separators)". So it includes both pass and trailing ;.

    However, I think pass should NOT be filtered out, because:

    • pass is often used intentionally (e.g., as a placeholder in empty function bodies)
    • A trailing ; is usually a mistake or stylistic choice

    Let me re-read the issue:

    In Python a trailing ; is a valid (if unusual) statement separator, so raise X; parses as raise X followed by an empty statement. That empty statement is technically unreachable, but reporting a no-op as actionable dead code is pure noise

    So the issue is specifically about the EMPTY statement produced by a trailing ;, not about pass. The empty statement is different from pass in that it has no semantic meaning.

    OK so the fix should filter out blocks that only contain empty NodeExpr nodes (with no Value).

    But wait, I need to verify that the parser actually produces empty NodeExpr for trailing ;. Let me check by running the actual parser.

    Actually, let me just implement the fix and test it. I'll add a helper function hasActionableCode that checks if a block contains at least one statement with semantic meaning.

    Let me define "hasActionableCode" as:

    • A block has actionable code if it contains at least one statement that is not an empty expression
    • An empty expression is a NodeExpr with no Value (and potentially no Body either)

    Wait, but what about other node types? Let me think about this more carefully.

    Actually, I think the simplest approach is:

    1. A block is "empty" if all its statements are "empty"
    2. A statement is "empty" if it's a NodeExpr with no Value and no Body
    3. A block with only "empty" statements should be filtered out

    Let me implement this.

    Actually wait, let me reconsider. The issue says the code is ";" and the column range is 0-0. This suggests the parser might be producing a different node type than I think.

    Let me just run the actual test to see what's happening:

    Actually, I already ran the test and got:

    {"function_name": "f", "location": {"start_line": 3, "start_column": 0, "end_column": 0}, "code": ";", "reason": "unreachable_branch", "severity": "warning"}
    

    So the code is ";". Let me trace through the code to understand why.

    The code field comes from getBlockCode, which uses getNodeDescription. For a NodeExpr, getNodeDescription returns "expression", not ";".

    So the parser must be producing a different node type. Let me check if there's a node type like ";".

    Actually, I think I need to look at the actual parser output. Let me write a small test to see what node type is produced for the trailing ;.

    OK let me just check what the parser produces for the test file:

    Let me look at how the parser handles the ; character. Maybe tree-sitter-python produces a semicolon node type that the parser doesn't recognize.

    Actually, I just realized something. The code field might not come from getNodeDescription. Let me check the dead code formatter more carefully.

    Looking at the JSON output:

    {"function_name": "f", "location": {"start_line": 3, "start_column": 0, "end_column": 0}, "code": ";", "reason": "unreachable_branch", "severity": "warning"}
    

    This matches the format of a finding. Let me check if there's a different path for generating the code field.

    Actually, looking at the domain's DeadCodeFinding:

    type DeadCodeFinding struct {
        ...
        Code        string           `json:"code"`
        ...
    }
    

    And the detector's DeadCodeFinding:

    type DeadCodeFinding struct {
        ...
        Code        string         `json:"code"`
        ...
    }
    

    Both have a Code field. The detector's Code comes from getBlockCode.

    But the issue says code: ";". Let me check if getBlockCode might return ";" for some reason.

    Looking at getBlockCode:

    func (dcd *DeadCodeDetector) getBlockCode(block *BasicBlock) string {
        if block == nil || len(block.Statements) == 0 {
            return ""
        }
    
        var codes []string
        for _, stmt := range block.Statements {
            nodeDesc := dcd.getNodeDescription(stmt)
            codes = append(codes, strings.TrimSpace(nodeDesc))
        }
        return strings.Join(codes, "\n")
    }
    

    For each statement, it gets the node description. For a NodeExpr, this would be "expression".

    But the issue says ";". So either:

    1. The parser produces a different node type
    2. There's a different code path

    Let me check if the parser might produce a node with type ";". Looking at tree-sitter, the ; character is parsed as a separator, not a statement. But maybe tree-sitter-python produces a semicolon node.

    Actually, let me just check the node types in the parser:

    const (
        ...
        NodeExpr             NodeType = "Expr"
        ...
    )
    

    If the parser produces a node type like ";", it would fall through to the default case in getNodeDescription:

    default:
        return string(node.Type)
    

    So if the node type is literally ";", the code would be ";".

    But wait, that doesn't make sense. Node types are strings like "Expr", "Return", etc. A node type of ";" would be very unusual.

    OK I think I need to just look at what the parser actually produces. Let me write a test script.

    Actually, let me just proceed with the fix. The key insight is that we need to filter out blocks that contain only empty/no-op statements. Whether the node type is NodeExpr, ";", or something else, the fix should be the same: check if the block contains only statements that carry no actionable code.

    Here's my plan:

    1. Add a helper function hasActionableCode that checks if a block contains at least one statement with semantic meaning
    2. Modify analyzeDeadBlock to skip blocks that don't have actionable code

    For the hasActionableCode function, I'll check if any statement is:

    • Not just an empty/no-op expression (NodeExpr with no Value and no Body)

    Actually, I think the cleanest approach is to define what makes a statement "actionable":

    • NodeExpr with a non-nil Value is actionable (it's a real expression)
    • NodeExpr with nil Value is NOT actionable (it's an empty statement, like trailing ;)
    • NodePass is NOT actionable (it's a no-op)
    • Other node types are actionable

    Wait, but the issue says to skip "empty statements (Python pass-equivalent / bare ; separators)". So pass should also be skipped.

    Let me define "actionable code" as:

    • Any statement that is not a no-op (not pass, not empty expression)

    But I'm concerned that filtering out pass might remove useful findings in some cases. For example:

    def foo():
        if False:
            pass
        return x
    

    Here, the pass is inside an unreachable if False: block. Should we report it as dead code?

    According to the issue:

    Empty statements (the no-op produced by a trailing ;) should be filtered out before emitting dead-code findings

    So the fix should specifically target trailing ; (empty expressions), not pass statements.

    OK let me finalize my plan:

    1. Add a helper function isEmptyStatement that checks if a statement is an empty expression
    2. Add a helper function hasActionableCode that checks if a block contains at least one non-empty statement
    3. Modify analyzeDeadBlock to skip blocks that don't have actionable code

    For isEmptyStatement, I'll check if:

    • The node type is NodeExpr (an expression statement)
    • AND the node has no Value (it's empty)

    Let me now implement the fix.

    Actually, wait. Let me look at the issue description again:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators) when collecting unreachable-branch findings in the dead-code analyzer.

    This says to skip "empty statements", which includes both pass and trailing ;. But the description also says:

    In Python a trailing ; is a valid (if unusual) statement separator, so raise X; parses as raise X followed by an empty statement.

    So the key distinction is between:

    • Empty statements (produced by trailing ;)
    • Pass statements (explicit pass)

    Both are no-ops, but they're different node types. The issue says to skip both.

    Hmm, but I'm still concerned about filtering out pass. Let me look at the issue description again:

    Empty statements (the no-op produced by a trailing ;) should be filtered out before emitting dead-code findings

    This specifically mentions trailing ;. I don't think the issue is asking to filter out pass statements.

    Actually, looking at the suggested fix:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators) when collecting unreachable-branch findings in the dead-code analyzer.

    The phrase "Python pass-equivalent / bare ; separators" suggests that the empty statement produced by a trailing ; is equivalent to pass. So the fix should target these empty statements, not necessarily all pass statements.

    OK let me think about this differently. What makes an empty statement "empty"?

    1. Empty NodeExpr - a NodeExpr with no Value/Body (produced by trailing ;)
    2. NodePass - explicit pass statement

    But pass is often intentional, so I think the fix should only target empty NodeExpr.

    Actually, you know what, let me just focus on the fix. The issue says:

    Empty statements (the no-op produced by a trailing ;) should be filtered out

    So I'll filter out blocks that contain only empty NodeExpr statements (with no Value).

    Now let me think about what happens with return y;. In this case, return y is a NodeReturn with a Value, and the trailing ; produces an empty NodeExpr. The empty NodeExpr ends up in its own block.

    So the fix is:

    1. Check if a block contains only empty NodeExpr statements (with no Value)
    2. If so, skip reporting it as dead code

    Let me implement this.

    Actually, I realized I should first understand the exact structure of the parser node. Let me look at the Node struct:

    type Node struct {
        Type    NodeType
        Name    string
        Value   interface{}
        Body    []*Node
        Orelse  []*Node
        Test    *Node
        ...
    }
    

    And NewNode:

    func NewNode(nodeType NodeType) *Node {
        return &Node{
            Type:   nodeType,
            Body:   make([]*Node, 0),
            Orelse: make([]*Node, 0),
        }
    }
    

    So a NodeExpr from an empty statement would have:

    • Type: NodeExpr
    • Value: nil
    • Body: [] (empty)

    And a NodeExpr from a real expression would have:

    • Type: NodeExpr
    • Value: <some node> (the expression node)

    OK so the check for an empty NodeExpr is simply stmt.Type == parser.NodeExpr && stmt.Value == nil.

    Now let me also think about edge cases:

    1. What if a block contains multiple statements, some empty and some not? We should still report the block because it has actionable code.
    2. What if a block contains only empty statements but also has a different node type? We should report the block because not all statements are empty.
    3. What about empty NodePass? Should we filter these out too? I think not, because pass is often intentional.

    Wait, but looking at the issue output again, the code is ";", not "expression". This means the parser is producing a different node type. Let me check if the parser might be producing a node type like ";".

    Actually, I think I should just look at the actual parser output. Let me write a test script.

    Actually, let me just proceed with the fix. I'll define "empty statement" as:

    • A NodeExpr with no Value AND no Body (completely empty expression)
    • Optionally, a NodePass (though I'm not sure)

    Wait, but if the parser produces a node type like ";" for the trailing ;, then my fix wouldn't work. Let me think about this differently.

    The issue says:

    Empty statements (the no-op produced by a trailing ;) should be filtered out

    So the fix should filter out blocks that only contain "empty" statements. An empty statement is one that carries no actionable code.

    What are the characteristics of an empty statement?

    1. It has no semantic meaning
    2. It doesn't affect program behavior
    3. It's typically a no-op

    In the Python parser, empty statements are produced by:

    • Trailing ; -> produces an empty expression statement
    • Possibly other sources

    Let me check if there's a common characteristic of empty statements in the parser.

    Actually, looking at buildExpressionStatement:

    func (b *ASTBuilder) buildExpressionStatement(tsNode *sitter.Node) *Node {
        childCount := int(tsNode.ChildCount())
        for i := 0; i < childCount; i++ {
            child := tsNode.Child(i)
            if child != nil && !b.isTrivia(child) {
                return b.buildNode(child)  // Returns the child node, not a new NodeExpr
            }
        }
    
        node := NewNode(NodeExpr)
        node.Location = b.getLocation(tsNode)
        return node  // Returns an empty NodeExpr with no children
    }
    

    When there are no meaningful children, it creates an empty NodeExpr with just a location. When there IS a meaningful child, it returns the child directly (not wrapped in a NodeExpr).

    So a real expression like x = 1; would produce an Assign node (not a NodeExpr), because the expression x = 1 is a child of the expression_statement.

    Wait, that doesn't sound right. Let me think about this more carefully.

    Actually, I think x = 1; would be parsed as an assignment node, not an expression_statement. The ; at the end is a separator, not part of the assignment.

    And raise X; would be parsed as a raise_statement followed by an empty expression_statement (for the ;).

    So the empty expression_statement would produce an empty NodeExpr.

    OK I'm pretty confident now that the fix should target empty NodeExpr statements. Let me implement it.

    Actually, wait. I just realized something. The issue says the code is ";", but my analysis says the parser produces a NodeExpr, which would give code: "expression". Let me check if maybe the issue description has a typo or if there's something else going on.

    Actually, looking at the issue description again, it says:

    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"}
    

    This is from the issue description. But when I ran the actual command, I didn't see the raw JSON. Let me check the actual JSON report again.

    Actually, I already checked the JSON report and didn't see the code field in the report. The findings in the report have description and reason fields, but not a code field directly. Let me check more carefully.

    Looking at the JSON report output:

    {
      "category": "dead_code",
      "severity": "warning",
      "effort": "moderate",
      "title": "Remove dead code after unreachable branch in 'g'",
      "description": "Code in this branch is unreachable under normal execution flow",
      ...
    }
    

    I don't see a code field here. So the code field might be in a different part of the report. Let me check the dead_code section of the report.

    Actually, looking at the dead_code section:

    "dead_code": {
        "files": [
            {
                "file_path": "/tmp/semi_repro.py",
                "functions": [
                    {
                        "name": "g",
                        "file_path": "/tmp/semi_repro.py",
                        "findings": [
                            {
                                "location": {
                                    ...
                                },
                                "reason": "unreachable_branch",
                                "severity": "warning",
                                "description": "Code in this branch is unreachable under normal execution flow",
                                "block_id": "bb3"
                            }
                        ],
                        ...
                    },
                    ...
                ],
                ...
            },
            ...
        ],
        ...
    }
    

    I don't see a code field here either. Let me check the function dead code struct more carefully.

    Looking at the domain's FunctionDeadCode:

    type FunctionDeadCode struct {
        Name     string `json:"name"`
        FilePath string `json:"file_path"`
        Findings []DeadCodeFinding `json:"findings"`
        ...
    }
    

    And DeadCodeFinding:

    type DeadCodeFinding struct {
        Location DeadCodeLocation `json:"location"`
        FunctionName string `json:"function_name"`
        Code        string           `json:"code"`
        Reason      string           `json:"reason"`
        Severity    DeadCodeSeverity `json:"severity"`
        Description string           `json:"description"`
        Context []string `json:"context,omitempty"`
        BlockID string `json:"block_id,omitempty"`
    }
    

    So the code field IS in the DeadCodeFinding. Let me check where this DeadCodeFinding is populated.

    Looking at the dead code service, the findings come from the detector. Let me trace the path from detector to report.

    Actually, let me just look at the dead_code_service.go to see how findings are converted:

    Let me check the dead code service to understand how the findings flow from the detector to the report.

    Actually, I think the code field in the issue description might be coming from a different source. Let me just focus on the fix.

    The key issue is: blocks containing only empty statements (produced by trailing ;) are being reported as dead code findings. This is noise because there's nothing actionable to remove.

    The fix should filter out such blocks. Let me implement the fix now.

    Here's my plan:

    1. Add a helper function hasActionableCode in dead_code.go that checks if a block contains at least one statement with semantic meaning
    2. Modify analyzeDeadBlock to skip blocks that don't have actionable code

    For hasActionableCode, I'll check if any statement is:

    • Not a NodeExpr with no Value (empty expression)

    Actually, let me also consider what happens with return y;. In this case, the CFG might have two blocks:

    1. Block with return y
    2. Block with empty NodeExpr (from trailing ;)

    The second block is unreachable and only contains an empty statement. The fix should filter this out.

    But wait, looking at the issue output:

    {"function_name": "f", "location": {"start_line": 3, "start_column": 0, "end_column": 0}, "code": ";", "reason": "unreachable_branch", "severity": "warning"}
    

    The start_line is 3 and start_column is 0. Line 3 of the test file is:

            raise ValueError("nope");
    

    So the ; is at the end of line 3. The column range 0-0 is strange - it suggests the empty statement's location has column 0.

    OK let me just look at the actual code to understand the structure better. Let me look at how blocks are created for raise X;:

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "processRaiseStatement" /pyscn/internal/analyzer/cfg_builder.go </tool_call>

  35. Qwen Assistant

    Let me search for how raise statements are handled in the CFG builder.

  36. Qwen Assistant

    Let me look at how raise statements are processed in the CFG builder.

  37. Qwen Assistant

    Let me now look at how processRaiseStatement handles the raise statement to understand the CFG structure.

  38. Qwen Assistant

    Let me look at the processRaiseStatement function to understand how raise statements are handled.

  39. Qwen Assistant

    Now I have a clear understanding of the issue. Let me implement the fix. The problem is that empty expression statements (produced by trailing semicolons) end up in unreachable blocks and get reported as dead code findings. I need to filter these out.

    Let me first write a test to verify the fix works:

  40. Qwen Assistant

    Now I understand the issue well. Let me implement the fix. The problem is that empty expression statements (produced by trailing semicolons like raise X; or return y;) end up in unreachable blocks and are incorrectly reported as dead code.

    Let me add a helper function to check if a block contains only empty/no-op statements, and modify analyzeDeadBlock to skip such blocks:

  41. Qwen Assistant

    The edit command didn't work properly. Let me try a different approach - use the replace command or try the edit command with proper syntax.

  42. Qwen Assistant

    Let me try with correct sed syntax.

  43. Qwen Assistant

    Let me use the replace command instead:

  44. Qwen Assistant

    Let me try to use the bash terminal to make the edit more reliably using Python or sed. Let me read the file content and then replace it.

  45. Qwen Assistant

    Now let me verify the changes were applied correctly:

  46. Qwen Assistant

    The changes have been applied correctly. Now let me build and test the fix:

  47. Qwen Assistant

    The build succeeded. Now let me test the fix by running the analyzer on the test file:

  48. Qwen Assistant

    The fix doesn't seem to have taken effect. Let me check the JSON report:

  49. Qwen Assistant

    The fix didn't work. The findings are still being reported. Let me investigate more carefully. The issue might be that the empty statement is not in its own block - it might be in the same block as the raise X or return y statement. Or perhaps the parser is producing a different node type than what I expected.

    Let me debug this by understanding what the parser actually produces for a trailing semicolon.

    Actually, wait. Looking at the findings more carefully:

    • Function 'f', start_line: 3 - this is the raise ValueError("nope"); line
    • Function 'g', start_line: 8 - this is the return y; line

    So the findings are pointing to the lines that have trailing semicolons. But my fix should have filtered these out if the blocks only contain empty statements.

    Let me think about this differently. Maybe the empty statement is in the SAME block as the raise X or return y, not in a separate block. In that case, the block would have actionable code (the raise X or return y), and my filter wouldn't remove it.

    But that doesn't make sense either, because if the empty statement is in the same block as the raise X, then the block is not unreachable (it contains the raise X which is reachable).

    Let me think about the CFG structure more carefully:

    For def f(x): if x is None: raise ValueError("nope"); return x:

    The CFG might look like:

    • Block 0 (entry): if x is None:
    • Block 1 (then): raise ValueError("nope");
    • Block 2 (else/fallthrough): return x
    • Block 3 (exit): exit

    But wait, the ; after raise ValueError("nope") is an empty statement. This empty statement might be parsed as a separate block that is unreachable.

    Actually, let me think about this more carefully. The raise ValueError("nope"); would be parsed as:

    • raise_statement containing raise ValueError("nope")
    • expression_statement containing nothing (the ;)

    The CFG builder processes statements in order. So:

    1. The raise_statement is processed, adding it to the current block
    2. The expression_statement (empty) is processed, adding it to the current block

    But wait, the raise_statement is a terminator, so it should end the block. Let me check if the CFG builder creates a new block after a terminator.

    Looking at processRaiseStatement:

    func (b *CFGBuilder) processRaiseStatement(stmt *parser.Node) {
        // Add raise statement to current block
        b.currentBlock.AddStatement(stmt)
        ...
    }
    

    It adds the raise statement to the current block, but I don't see where it creates a new block. So the ; would be added to the SAME block as the raise X.

    But that doesn't explain the issue, because if the block contains both raise X and the empty ;, then:

    1. The block is reachable (it's the then branch of the if)
    2. The block has actionable code (the raise X)
    3. So the finding should not be for this block

    Let me look at the CFG structure more carefully. Maybe the issue is with how the CFG builder handles the empty statement after the terminator.

    Actually, I think I need to understand the CFG structure better. Let me add some debugging to understand what's happening.

    Actually, let me re-read the issue description:

    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"}
    

    The code is ";" and the column range is 0-0. This suggests the finding is for a block that contains ONLY the empty ; statement, not a block that contains both raise X and ;.

    So the CFG builder must be creating a separate block for the ; statement. Let me check how the CFG builder handles this.

    Actually, looking at the issue more carefully, the start_line is 3, which is the line of raise ValueError("nope");. And the code is ";". So the finding is for a block that starts on line 3 and contains only the ; statement.

    But my fix should have filtered this out if the block only contains empty NodeExpr statements. Let me check if the empty statement is actually a NodeExpr with Value == nil.

    Wait, maybe the parser is producing a different node type for the ;. Let me check by looking at the parser output.

    Actually, let me add some debugging to understand what node type is being produced.

    Hmm, but I can't easily add debugging to the Go code. Let me think about this differently.

    The issue says code: ";". My blockHasActionableCode function checks for NodeExpr with Value == nil. If the node type is not NodeExpr, then my filter wouldn't catch it.

    Let me check what node type tree-sitter produces for the ; separator.

    Actually, looking at the tree-sitter-python grammar, the ; is parsed as a separator or maybe it's just trivia. The expression_statement would be parsed with the empty content.

    But wait, in Python, raise X; would be parsed as:

    • raise_statement containing raise X
    • The ; is a separator

    Tree-sitter might not produce a separate expression_statement for the ;. Instead, it might produce a single raise_statement node.

    So the issue might not be about the parser producing an empty expression_statement. Instead, the issue might be about how the dead code analyzer is reporting findings.

    Let me re-read the issue:

    In Python a trailing ; is a valid (if unusual) statement separator, so raise X; parses as raise X followed by an empty statement.

    Hmm, but Python itself doesn't have a concept of "empty statement" for ;. The ; is just a statement separator. raise X; is equivalent to raise X followed by a new statement, but there's no statement after the ; in the source code.

    Wait, actually in Python, raise X; is parsed as raise X followed by an empty statement (or just raise X with the ; being a separator and nothing after it). Python's grammar allows ; as a separator, but an empty statement after ; is not valid Python.

    Let me test this in Python:

    >>> def f(x):
    ...     if x is None:
    ...         raise ValueError("nope");
    ...     return x
    ...
    >>> f(None)
    Traceback (most recent call last):
      File "<stdin>", line 3, in <module>
    ValueError: nope
    

    OK so Python accepts this. The ; after raise ValueError("nope") is just a separator, and there's no empty statement after it.

    But tree-sitter might parse it differently. Let me check what tree-sitter-python produces for raise X;.

    Actually, I think the issue might be that tree-sitter-python parses raise X; as:

    • raise_statement containing raise X
    • expression_statement containing nothing (empty)

    This would explain why the dead code analyzer is reporting a finding for the empty expression_statement.

    But wait, my fix checks for NodeExpr with Value == nil. If tree-sitter produces an empty expression_statement, the parser would create a NodeExpr with no Value. So my fix should catch this.

    Unless... the issue is that the empty statement is not a NodeExpr with Value == nil, but something else entirely.

    Let me check if there's a NodeEmpty or similar node type.

    Looking at the parser's node types:

    NodeExpr             NodeType = "Expr"
    NodePass             NodeType = "Pass"
    

    There's no NodeEmpty. So the empty statement must be represented as something else.

    Actually, let me re-read the buildExpressionStatement function:

    func (b *ASTBuilder) buildExpressionStatement(tsNode *sitter.Node) *Node {
        childCount := int(tsNode.ChildCount())
        for i := 0; i < childCount; i++ {
            child := tsNode.Child(i)
            if child != nil && !b.isTrivia(child) {
                return b.buildNode(child)
            }
        }
    
        node := NewNode(NodeExpr)
        node.Location = b.getLocation(tsNode)
        return node
    }
    

    When there are no meaningful children, it creates a NodeExpr with just a location. So the empty expression_statement would produce a NodeExpr with Value == nil.

    OK so my fix should catch this. But it's not working. Let me check if the issue is with how the empty statement is being added to the CFG.

    Actually, wait. Let me re-read the issue:

    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"}
    

    The start_column is 0 and end_column is 0. This is a very unusual column range. Let me check if the parser might be producing a node with these column values.

    Looking at getLocation:

    func (b *ASTBuilder) getLocation(tsNode *sitter.Node) Location {
        return Location{
            File:        b.filePath,
            StartLine:   int(tsNode.StartRow()) + 1,
            StartColumn: int(tsNode.StartColumn()),
            EndLine:     int(tsNode.EndRow()) + 1,
            EndColumn:   int(tsNode.EndColumn()),
        }
    }
    

    So the column values come from tree-sitter. If tree-sitter reports column 0 for the empty statement, then the Location would have column 0.

    But wait, the issue says start_column: 0 and end_column: 0. If the ; is at column 25 (end of line), the column should be 25, not 0.

    Hmm, maybe the issue is that tree-sitter doesn't produce a separate node for the ; at all. Instead, the ; might be parsed as part of the raise_statement, and the "empty statement" is a phantom node that the parser creates.

    Actually, let me think about this differently. Maybe the issue is not about the parser producing an empty node, but about the CFG builder creating a separate block for the ;.

    Let me look at how the CFG builder handles statements. After processing a raise statement (which is a terminator), does the CFG builder create a new block for subsequent statements?

    Looking at processRaiseStatement:

    func (b *CFGBuilder) processRaiseStatement(stmt *parser.Node) {
        // Add raise statement to current block
        b.currentBlock.AddStatement(stmt)
        ...
    }
    

    It adds the raise statement to the current block, but I don't see where it creates a new block. However, looking at the processStatement function:

    func (b *CFGBuilder) processStatement(stmt *parser.Node) {
        ...
        case parser.NodeRaise:
            b.processRaiseStatement(stmt)
        ...
    }
    

    The raise statement is processed, but I don't see where a new block is created. So subsequent statements would be added to the same block.

    But wait, the issue is about finding dead code after a raise. If the raise and the subsequent statement are in the same block, then the block would be reachable (because it contains the raise), and there would be no dead code finding.

    So the issue must be that the CFG builder is creating a separate block for the empty statement after the raise.

    Let me look at how the CFG builder handles statement sequences. After processing a terminator (like raise), does it create a new block?

    Actually, looking at the processIfStatement function:

    func (b *CFGBuilder) processIfStatement(stmt *parser.Node) {
        ...
        // Create then branch
        thenBlock := b.createBlock("if_then")
        b.cfg.ConnectBlocks(conditionBlock, thenBlock, EdgeCondTrue)
        
        // Create else branch
        elseBlock := b.createBlock("if_else")
        b.cfg.ConnectBlocks(conditionBlock, elseBlock, EdgeCondFalse)
        ...
    }
    

    For if statements, the builder creates separate blocks for then and else branches. And if the then branch ends with a terminator (like raise), the blockTerminates function checks if the block is terminated:

    func (b *CFGBuilder) blockTerminates(block *BasicBlock) bool {
        if block == nil || len(block.Statements) == 0 {
            return false
        }
    
        lastStmt := block.Statements[len(block.Statements)-1]
        return lastStmt.Type == parser.NodeReturn ||
            lastStmt.Type == parser.NodeRaise ||
            lastStmt.Type == parser.NodeBreak ||
            lastStmt.Type == parser.NodeContinue
    }
    

    So if the then branch ends with raise, the block is considered terminated. But the issue is about the empty statement after the raise.

    Let me think about this more carefully. For:

    def f(x):
        if x is None:
            raise ValueError("nope");
        return x
    

    The CFG might look like:

    • Block 0 (entry): if x is None:
    • Block 1 (then): raise ValueError("nope");
    • Block 2 (else): return x
    • Block 3 (exit): exit

    But where is the empty ; statement? If it's in the same block as raise ValueError("nope"), then the block would have two statements: raise and empty expression. The block would still be reachable (it's the then branch of the if), so there would be no dead code finding.

    But the issue says there IS a dead code finding for the empty statement. So the empty statement must be in a separate block.

    Actually, wait. Let me re-read the issue:

    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"}
    

    The finding is for line 3 (the line with raise ValueError("nope");). The code is ";". So the finding is about a block that starts on line 3 and contains the ; statement.

    But wait, the reason is unreachable_branch, not unreachable_after_raise. This suggests the finding is for a block that is part of a conditional branch (the if statement), not a block that follows a raise.

    Hmm, let me think about this more carefully. The if x is None: branch has two parts:

    1. The raise ValueError("nope") statement
    2. The empty ; statement

    If these are in separate blocks:

    • Block 1a: raise ValueError("nope") (reachable)
    • Block 1b: ; (empty, unreachable)

    The issue might be that the CFG builder creates a new block for the empty ; statement after the raise. But I don't see code in the CFG builder that does this.

    Actually, wait. Looking at the processRaiseStatement function again, I see that it handles exception handling (try/finally blocks). Let me look at the full function:

    func (b *CFGBuilder) processRaiseStatement(stmt *parser.Node) {
        // Add raise statement to current block
        b.currentBlock.AddStatement(stmt)
        
        // Find the next finally block...
        var targetFinallyBlock *BasicBlock
        var fallbackExceptionCtx *exceptionContext
        for i := len(b.exceptionStack) - 1; i >= 0; i-- {
            ...
        }
        ...
    }
    

    It adds the raise statement to the current block, but doesn't create a new block. So subsequent statements would be added to the same block.

    But wait, I think the issue might be different. Let me look at the CFG structure more carefully.

    Actually, I think I've been misunderstanding the issue. Let me re-read it:

    In Python a trailing ; is a valid (if unusual) statement separator, so raise X; parses as raise X followed by an empty statement.

    So Python parses raise X; as raise X followed by an empty statement. The empty statement is a no-op that does nothing.

    Now, the dead code analyzer reports this empty statement as unreachable dead code. This is technically correct (the empty statement IS unreachable), but it's noise because there's nothing actionable to remove.

    So the issue is that the dead code analyzer is reporting a finding for a block that contains ONLY the empty statement (not a block that contains both the raise and the empty statement).

    This means the CFG builder must be creating a separate block for the empty statement. Let me check how this happens.

    Actually, I think the CFG builder might be creating a new block after processing a terminator. Let me search for code that creates blocks after terminators:

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "terminates|terminator|newBlock|createBlock" /pyscn/internal/analyzer/cfg_builder.go | head -30 </tool_call>

  50. Qwen Assistant

    Let me search for how blocks are created and connected in the CFG builder.

  51. Qwen Assistant

    Let me look at the code that creates unreachable blocks:

  52. Qwen Assistant

    I see that when all branches of an if statement terminate, the CFG builder creates an "unreachable" block. But this is for the merge point, not for statements after a terminator.

    Let me understand the flow better. For:

    def f(x):
        if x is None:
            raise ValueError("nope");
        return x
    

    The CFG would be:

    1. Entry block: if x is None:
    2. Then block: raise ValueError("nope"); - this is the then branch
    3. Else block: return x - this is the else branch
    4. Merge block (unreachable): because all branches terminate

    The ; statement (empty expression) would be part of the then block, along with the raise statement. So the then block would have two statements: raise and empty NodeExpr.

    But then the finding should be for the unreachable merge block, not for the then block. Let me check if the unreachable merge block contains any statements.

    Actually, looking at the code:

    if b.allBranchesTerminate(thenEndBlock, elseEndBlock, true) {
        // All branches terminate - don't connect to merge, make it unreachable
        b.currentBlock = b.createBlock(LabelUnreachable)
        return
    }
    

    When all branches terminate, an unreachable block is created, but it's empty (no statements added to it). The return statement at the end of processIfStatement ensures we don't add any more statements to this unreachable block.

    So the unreachable merge block would be empty (no statements), and the GetUnreachableBlocksWithStatements function would filter it out.

    But the issue says there ARE findings for the empty statement. So maybe the issue is different.

    Actually, let me re-read the issue more carefully. The issue says:

    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"}
    

    The code is ";". This is the code field of the finding. Looking at getBlockCode:

    func (dcd *DeadCodeDetector) getBlockCode(block *BasicBlock) string {
        if block == nil || len(block.Statements) == 0 {
            return ""
        }
    
        var codes []string
        for _, stmt := range block.Statements {
            nodeDesc := dcd.getNodeDescription(stmt)
            codes = append(codes, strings.TrimSpace(nodeDesc))
        }
    
        return strings.Join(codes, "\n")
    }
    

    For a block with an empty NodeExpr (produced by trailing ;), getNodeDescription would return "expression". So the code should be "expression", not ";".

    But the issue says code: ";". This is very confusing.

    Wait, let me check if the issue description is from a different version of the code. The issue says:

    pyscn version: v1.22.5 (commit bac7f16)

    Maybe the current code (which I'm modifying) is different from v1.22.5.

    Let me check the git log to see what version we're at:

    Actually, the issue might be that the parser is producing a different node type. Let me check if tree-sitter-python has a specific node type for the ; character.

    Actually, I think the issue might be that tree-sitter-python doesn't parse the ; as a separate node. Instead, the ; is just a separator in the source code, and the parser produces the statements without any node for the ;.

    So for raise X;, the parser would produce:

    • raise_statement containing raise X
    • No separate node for the ;

    And the ; is just trivia (whitespace/comment that tree-sitter ignores).

    But then how does the dead code analyzer produce a finding with code: ";"?

    Actually, wait. Let me re-read the issue:

    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"}
    

    Maybe the code: ";" is a typo or artifact of the issue description. The actual code field might be something else.

    Let me run the actual analyzer and check what the code field is:

    Actually, I already ran the analyzer and the JSON report doesn't show the code field directly. The report has description and reason fields, but not a code field.

    Let me check the dead_code section of the report more carefully:

    <tool_call> <function=bash_terminal> <parameter=command> python3 -c " import json with open('/pyscn/.pyscn/reports/analyze_20260726_195452.json') as f: data = json.load(f) for file_data in data.get('dead_code', {}).get('files', []): print('File:', file_data.get('file_path')) for func_data in file_data.get('functions', []): print(' Function:', func_data.get('name')) for finding in func_data.get('findings', []): print(' Finding:', json.dumps(finding, indent=6)) " </tool_call>

  53. Qwen Assistant

    The user is asking me to run a command to check the dead code section of the report. Let me run this command properly.

  54. Qwen Assistant

    The findings show code: ";" with start_column: 0, end_column: 0. This confirms the issue - the parser is producing a node that represents the ; character, and the dead code detector is reporting it as dead code.

    Now I need to understand why my fix didn't work. Let me think about this more carefully.

    The finding shows code: ";", which means the getBlockCode function is returning ";". Looking at getNodeDescription:

    func (dcd *DeadCodeDetector) getNodeDescription(node *parser.Node) string {
        if node == nil {
            return ""
        }
    
        switch node.Type {
        case parser.NodeReturn:
            return "return"
        case parser.NodeBreak:
            return "break"
        ...
        case parser.NodeExpr:
            return "expression"
        ...
        default:
            return string(node.Type)
        }
    }
    

    If the code is ";", then the node type must be ";". This is very unusual - node types are typically strings like "Expr", "Return", etc.

    Wait, but the Node.Type is a NodeType which is string. If tree-sitter produces a node type like ";", then the getNodeDescription function would return ";" for that node type.

    So the parser IS producing a node with type ";". This means tree-sitter-python has a specific node type for the ; character.

    My fix checks for NodeExpr with Value == nil, but if the node type is ";", my fix wouldn't catch it.

    I need to update my fix to also catch node types that are just punctuation characters (like ;).

    Actually, let me think about this differently. The issue is that the parser is producing a node for the ; character. This node has type ";" (the literal semicolon). My fix should check for this case.

    But wait, what node type is this? Let me look at the parser's node types:

    Looking at the parser, I don't see a node type for ;. So this must be an unrecognized node type that falls through to the default case.

    Actually, let me check if there's a node type that represents empty statements or semicolons. Let me search the parser code:

    Actually, I think the issue is that tree-sitter-python produces a separator or semicolon node for the ; character. The pyscn parser doesn't recognize this node type, so it falls through to the default case in getNodeDescription, returning ";".

    Let me check the parser's buildNode function to see how it handles unrecognized node types:

    Looking at the parser code, I see that buildNode has a switch statement that handles various node types. If the node type is not recognized, it might create a generic node with the node type as the type.

    Actually, looking at the issue more carefully, the code field is ";". This means the parser is creating a node with type ";". But how?

    Let me check the parser's handling of unrecognized node types:

    Looking at buildNode:

    func (b *ASTBuilder) buildNode(tsNode *sitter.Node) *Node {
        switch tsNode.Type() {
        ...
        default:
            // Create a generic node for unrecognized types
            return b.buildGenericNode(tsNode)
        }
    }
    

    And buildGenericNode:

    func (b *ASTBuilder) buildGenericNode(tsNode *sitter.Node) *Node {
        node := NewNode(NodeType(tsNode.Type()))
        node.Location = b.getLocation(tsNode)
        return node
    }
    

    So for unrecognized node types, the parser creates a node with the tree-sitter type as the node type. If tree-sitter produces a ";" type, the parser would create a node with type ";".

    This explains why code: ";" - the parser is producing a node with type ";" for the ; character.

    Now I need to update my fix to catch this case. Instead of checking for NodeExpr with Value == nil, I should check if the node type is ";" or if the node is essentially empty.

    Actually, looking at the issue again, I realize the problem might be simpler. The parser is producing a node with type ";" for the trailing semicolon. This is a "separator" node type from tree-sitter-python.

    My fix should check for this case. Let me update the blockHasActionableCode function to also catch nodes with punctuation types (like ";").

    Actually, let me think about what makes a node "empty" or "no-op":

    1. NodeExpr with no Value - an empty expression
    2. NodePass - a pass statement
    3. Any node with type that is a punctuation character (like ";")

    But checking for punctuation types is fragile. A better approach might be to check if the node has any semantic meaning.

    Actually, looking at the issue description:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators) when collecting unreachable-branch findings in the dead-code analyzer.

    The issue suggests skipping nodes that are "empty statements" or "bare ; separators". This includes:

    1. Empty expression statements (NodeExpr with no Value)
    2. Pass statements (NodePass)
    3. Separator nodes (like ";")

    Let me update my fix to also check for node types that are just punctuation characters.

    Actually, a better approach might be to check if the node type is in a list of "empty" types:

    1. NodeExpr with no Value
    2. NodePass
    3. Any node type that is a single punctuation character (like ";", :, etc.)

    Or even simpler: check if the node type starts with a punctuation character (like ;, :, (, ), etc.).

    Actually, let me look at what tree-sitter-python produces for the ; character. The ; is a separator in Python grammar, so it might be parsed as a separator node type. But the issue says code: ";", which means the node type is literally ";".

    Let me update my fix to check for node types that are punctuation characters.

    Wait, but how do I know what the node type is? Let me add some debugging to understand this.

    Actually, I can check by looking at the parser's code. Let me search for how the parser handles the ; character:

    Looking at the parser, I don't see specific handling for the ; character. So it must be falling through to the default case, which creates a node with the tree-sitter type as the node type.

    The tree-sitter-python grammar likely produces a separator or semicolon node type for the ; character. But the issue says code: ";", which means the node type is literally ";".

    OK let me just update my fix to also catch node types that are punctuation characters. I'll check if the node type is a single punctuation character (like ";", :, etc.).

    Actually, let me think about this more carefully. The issue says code: ";", but this might just be the node type being returned by getNodeDescription. Let me check what the node type actually is.

    Looking at getNodeDescription:

    default:
        return string(node.Type)
    

    So if the node type is ";", the code would be ";". This confirms that the node type is literally ";".

    But how does the parser produce a node with type ";"? Let me check the parser's handling of unrecognized node types.

    Looking at buildNode:

    func (b *ASTBuilder) buildNode(tsNode *sitter.Node) *Node {
        switch tsNode.Type() {
        case "pass_statement":
            return b.buildPassStatement(tsNode)
        case "expression_statement":
            return b.buildExpressionStatement(tsNode)
        ...
        default:
            // Create a generic node for unrecognized types
            return b.buildGenericNode(tsNode)
        }
    }
    

    And buildGenericNode:

    func (b *ASTBuilder) buildGenericNode(tsNode *sitter.Node) *Node {
        node := NewNode(NodeType(tsNode.Type()))
        node.Location = b.getLocation(tsNode)
        return node
    }
    

    So for unrecognized node types, the parser creates a node with the tree-sitter type as the node type. If tree-sitter-python produces a ";" type, the parser would create a node with type ";".

    But wait, tree-sitter node types are typically alphanumeric strings like "pass_statement", "expression_statement", etc. A node type of ";" would be very unusual.

    Let me check if tree-sitter-python has a ";" node type. Actually, looking at the tree-sitter-python grammar, the ; is a literal character in the grammar, not a named node type. So tree-sitter wouldn't produce a node with type ";".

    Hmm, but the issue says code: ";". This must mean the parser is creating a node with type ";" for some reason.

    Actually, let me check if the parser might be producing a node with type ";" from the ; character being treated as trivia. Or maybe the parser is using a different approach to handle the ; character.

    OK let me just try a different approach. Instead of checking for specific node types, let me check if the node has any "actionable" properties. A node is "actionable" if:

    1. It has a non-empty Value (for expression nodes)
    2. It has a non-empty Body (for compound statements)
    3. It has a non-empty Name (for named entities)

    If a node has none of these, it's effectively empty and should be skipped.

    Let me update my fix to check for this:

    func (dcd *DeadCodeDetector) blockHasActionableCode(block *BasicBlock) bool {
        if block == nil || len(block.Statements) == 0 {
            return false
        }
    
        for _, stmt := range block.Statements {
            if stmt == nil {
                continue
            }
            // Skip empty expression statements (produced by trailing semicolons)
            if stmt.Type == parser.NodeExpr && stmt.Value == nil {
                continue
            }
            // Skip empty pass statements
            if stmt.Type == parser.NodePass {
                continue
            }
            // Skip nodes with no meaningful content (e.g., bare semicolons)
            // A node has meaningful content if it has a Value, Body, Name, or Test
            if stmt.Value == nil && len(stmt.Body) == 0 && stmt.Name == "" && stmt.Test == nil {
                continue
            }
            // This statement has actionable code
            return true
        }
    
        // All statements are empty/no-op
        return false
    }
    

    Wait, but this would skip too many nodes. A return statement has Value (the returned value), so it wouldn't be skipped. An if statement has Test, Body, and Orelse, so it wouldn't be skipped. But a raise statement might have Value (the exception), so it wouldn't be skipped.

    But what about a node that's just a bare ;? It would have:

    • Value == nil
    • Body == nil or []
    • Name == ""
    • Test == nil

    So my check would correctly identify it as empty.

    But what about a node that represents some other syntax element? For example, a : (colon) might be parsed as a separate node. If the node has no meaningful properties, it should be skipped.

    Actually, let me think about this more carefully. The issue is specifically about trailing semicolons, which produce nodes with no meaningful content. My check should be:

    • Skip nodes that have no Value, no Body, no Name, and no Test

    This would catch:

    • Empty NodeExpr (trailing ;)
    • Any other node with no meaningful content

    But would it catch NodePass? Let me check:

    • NodePass has no Value, no Body, no Name, no Test
    • So it would be skipped by my check

    This is consistent with the issue's suggestion to skip "empty statements (Python pass-equivalent / bare ; separators)".

    OK let me update my fix with this approach:

    Actually, wait. Let me reconsider. The issue says to skip "empty statements (Python pass-equivalent / bare ; separators)". This suggests:

    1. Empty ; separators - these are nodes with no meaningful content
    2. pass-equivalent nodes - these might be NodePass or other no-op nodes

    My check should skip nodes that have no meaningful content. But I need to be careful not to skip legitimate statements.

    Let me think about what makes a statement "actionable":

    • NodeReturn with Value - actionable (returns a value)
    • NodeReturn with no Value - actionable (returns None, but the statement itself has meaning)
    • NodeRaise with Value - actionable (raises an exception)
    • NodeRaise with no Value - actionable (re-raises the current exception)
    • NodeExpr with Value - actionable (evaluates an expression)
    • NodeExpr with no Value - NOT actionable (empty expression, produced by trailing ;)
    • NodePass - NOT actionable (explicit no-op)
    • NodeAssign - actionable (assignment)
    • NodeIf with Test - actionable (conditional)
    • etc.

    Hmm, the issue is distinguishing between:

    1. Statements that have semantic meaning (even if no-op like pass)
    2. Statements that are truly empty (like trailing ;)

    The pass statement is explicitly written by the user, so it has semantic meaning (the user intentionally wrote a no-op). But a trailing ; is usually a mistake or stylistic choice, and it produces a node with no semantic meaning.

    But both pass and trailing ; are no-ops, so from a dead code perspective, they're equivalent. The issue suggests filtering out both.

    OK let me update my fix to skip nodes that have no meaningful content. I'll check if the node has any of: Value, Body, Name, Test, or Children.

    Actually, wait. Let me look at the Node structure more carefully:

    type Node struct {
        Type    NodeType
        Name    string
        Value   interface{}
        Body    []*Node
        Orelse  []*Node
        Test    *Node
        ...
    }
    

    And the Children field:

    type Node struct {
        ...
        Children []*Node
        ...
    }
    

    Wait, I don't see Children in the Node struct. Let me check:

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "type Node struct" /pyscn/internal/parser/ast.go -A 30 </tool_call>

  55. Qwen Assistant

    The user is asking me to run a command to check the Node struct definition. Let me do that.

  56. Qwen Assistant

    Good, I can see the Node struct. It has Children []*Node at line 117. Now let me understand the issue better.

    The code: ";" in the finding means the parser is producing a node with type ";". This is an unrecognized node type from tree-sitter-python.

    Let me check the buildGenericNode function to understand how unrecognized node types are handled:

  57. Qwen Assistant

    The buildGenericNode function doesn't exist in the parser. Let me check how unrecognized node types are handled in the parser.

  58. Qwen Assistant

    I see! Looking at the parser's buildNode function, when it encounters an unrecognized node type, it creates a generic node:

    default:
        // For unhandled types, create a generic node with children
        node := NewNode(NodeType(nodeType))
        node.Location = b.getLocation(tsNode)
    

    So for a ; separator node type, the parser creates a node with type ";" (the literal semicolon character). This node would have:

    • Type: ";"
    • Value: nil (default from NewNode)
    • Body: [] (default from NewNode)
    • Children: [] (default from NewNode)
    • etc.

    My current fix checks for NodeExpr with Value == nil, but the node type here is ";", not NodeExpr. So my fix doesn't catch it.

    I need to update my fix to also catch nodes that are essentially empty, regardless of their type. The key insight is that a truly empty node would have:

    • No Value
    • No Body
    • No Name
    • No Test
    • No Children

    Let me update my fix to check for this condition.

    Actually, wait. Let me re-think this. The issue says:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators) when collecting unreachable-branch findings in the dead-code analyzer.

    The key phrase is "empty statements". A truly empty statement is one that:

    1. Has no semantic meaning
    2. Doesn't affect program behavior
    3. Is essentially a no-op

    In the context of dead code detection, we want to filter out nodes that are:

    1. Empty NodeExpr (produced by trailing ;)
    2. NodePass (explicit no-op)
    3. Any other node with no meaningful content

    The best approach is to check if a node has any meaningful content. A node has meaningful content if:

    1. It has a Value (for expressions, assignments, etc.)
    2. It has a Body (for compound statements)
    3. It has a Name (for named entities)
    4. It has a Test (for conditionals)
    5. It has Children that are meaningful (for generic nodes)

    But this is getting complicated. Let me simplify:

    A node is "empty" if it has no Value, no Body, no Name, and no Test. This would catch:

    1. Empty NodeExpr (trailing ;)
    2. NodePass (explicit no-op)
    3. Any generic node with no content (like a bare ;)

    But wait, NodePass is explicitly written by the user, so it has semantic meaning. The issue says to skip "empty statements (Python pass-equivalent / bare ; separators)", which suggests pass should also be skipped.

    Actually, looking at the issue description again:

    Empty statements (the no-op produced by a trailing ;) should be filtered out before emitting dead-code findings

    The issue specifically mentions "the no-op produced by a trailing ;". This suggests the fix should target trailing ; statements, not all pass statements.

    But the issue also says:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators)

    This suggests both pass and trailing ; should be skipped.

    OK let me just update my fix to skip both empty NodeExpr and NodePass, as well as any node with no meaningful content.

    Actually, let me reconsider. The issue is about trailing ; producing empty statements. The parser creates a node with type ";" for these. My fix should catch this case.

    The simplest fix is to check if a node has any meaningful content. If it doesn't, it's an empty statement and should be skipped.

    A node has meaningful content if:

    1. It has a non-nil Value
    2. It has a non-empty Body
    3. It has a non-empty Name
    4. It has a non-nil Test

    If none of these are true, the node is empty and should be skipped.

    Let me update my fix:

    func (dcd *DeadCodeDetector) blockHasActionableCode(block *BasicBlock) bool {
        if block == nil || len(block.Statements) == 0 {
            return false
        }
    
        for _, stmt := range block.Statements {
            if stmt == nil {
                continue
            }
            // Check if this statement has any meaningful content
            // A statement is "empty" if it has no Value, Body, Name, or Test
            hasContent := stmt.Value != nil ||
                len(stmt.Body) > 0 ||
                stmt.Name != "" ||
                stmt.Test != nil ||
                len(stmt.Children) > 0
            if !hasContent {
                continue
            }
            // This statement has actionable code
            return true
        }
    
        // All statements are empty/no-op
        return false
    }
    

    Wait, but this would skip too many nodes. For example, a return statement with no value (return; or just return) would have:

    • Value: nil (no value)
    • Body: [] (no body)
    • Name: "" (no name)
    • Test: nil (no test)
    • Children: [] (no children)

    So it would be considered empty and skipped. But return is a valid statement with semantic meaning, even if it doesn't return a value.

    Hmm, this is tricky. Let me think about what makes a statement "actionable" from a dead code perspective:

    1. A statement that affects program state (assignments, function calls, etc.)
    2. A statement that affects control flow (returns, raises, breaks, continues)
    3. A statement that has side effects (prints, etc.)

    Empty statements (like trailing ;) don't have any of these properties. They're just placeholders that do nothing.

    So the question is: how do we distinguish between a statement that does nothing (like pass or trailing ;) and a statement that has semantic meaning (like return)?

    One approach is to check the node type:

    • NodeExpr with no Value -> empty (skip)
    • NodePass -> empty (skip)
    • ; (bare separator) -> empty (skip)
    • Everything else -> has semantic meaning (don't skip)

    This approach is more targeted and less likely to have false negatives.

    Let me update my fix to use this approach:

    func (dcd *DeadCodeDetector) blockHasActionableCode(block *BasicBlock) bool {
        if block == nil || len(block.Statements) == 0 {
            return false
        }
    
        for _, stmt := range block.Statements {
            if stmt == nil {
                continue
            }
            // Skip empty expression statements (produced by trailing semicolons)
            if stmt.Type == parser.NodeExpr && stmt.Value == nil {
                continue
            }
            // Skip empty pass statements
            if stmt.Type == parser.NodePass {
                continue
            }
            // Skip bare separator nodes (like `;` produced by tree-sitter)
            // These are nodes with punctuation character types
            if isPunctuationNodeType(stmt.Type) {
                continue
            }
            // This statement has actionable code
            return true
        }
    
        // All statements are empty/no-op
        return false
    }
    
    // isPunctuationNodeType checks if a node type is a punctuation character
    func isPunctuationNodeType(nodeType parser.NodeType) bool {
        // Check if the node type is a single punctuation character
        s := string(nodeType)
        if len(s) == 1 {
            c := s[0]
            return c == ';' || c == ':' || c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' || c == ',' || c == '.' || c == '<' || c == '>' || c == '=' || c == '!' || c == '+' || c == '-' || c == '*' || c == '/' || c == '%' || c == '&' || c == '|' || c == '^' || c == '~'
        }
        return false
    }
    

    Wait, this is getting too complicated. And it might miss some node types.

    Let me think about this differently. The issue is that the parser produces a node with type ";" for trailing semicolons. This node has no meaningful content.

    The simplest fix is to check if the node type starts with a punctuation character (like ;). This would catch all nodes that represent punctuation separators.

    Actually, let me look at what tree-sitter-python produces for the ; character. The ; is a separator in Python grammar, so it might be parsed as a separator or semicolon node type. But the issue says code: ";", which means the node type is literally ";".

    OK let me just check if the node type is ";" or if it's a punctuation character. If so, skip it.

    Actually, let me take a step back. The issue is about trailing semicolons producing empty statements. The fix should filter out these empty statements.

    The most robust approach is to check if a node has any meaningful content. A node has meaningful content if:

    1. It's not just a separator or punctuation character
    2. It has at least one of: Value, Body, Name, Test, Children (with meaningful children)

    Let me implement this more carefully:

    func (dcd *DeadCodeDetector) blockHasActionableCode(block *BasicBlock) bool {
        if block == nil || len(block.Statements) == 0 {
            return false
        }
    
        for _, stmt := range block.Statements {
            if stmt == nil {
                continue
            }
            // Skip nodes with no meaningful content
            if !dcd.hasActionableNode(stmt) {
                continue
            }
            // This statement has actionable code
            return true
        }
    
        // All statements are empty/no-op
        return false
    }
    
    // hasActionableNode checks if a node has meaningful content
    func (dcd *DeadCodeDetector) hasActionableNode(node *parser.Node) bool {
        // Empty expression statements (NodeExpr with no Value) are not actionable
        if node.Type == parser.NodeExpr && node.Value == nil {
            return false
        }
        
        // Pass statements are not actionable (they're explicit no-ops)
        if node.Type == parser.NodePass {
            return false
        }
        
        // Bare separator nodes (like `;`) are not actionable
        // These are nodes whose type is a punctuation character
        if isPunctuationNodeType(node.Type) {
            return false
        }
        
        // Nodes with no meaningful content are not actionable
        if node.Value == nil && len(node.Body) == 0 && node.Name == "" && node.Test == nil {
            return false
        }
        
        return true
    }
    
    // isPunctuationNodeType checks if a node type is a punctuation character
    func isPunctuationNodeType(nodeType parser.NodeType) bool {
        s := string(nodeType)
        if len(s) == 1 {
            c := s[0]
            return c == ';' || c == ':' || c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' || c == ',' || c == '.' || c == '<' || c == '>' || c == '=' || c == '!' || c == '+' || c == '-' || c == '*' || c == '/' || c == '%' || c == '&' || c == '|' || c == '^' || c == '~'
        }
        return false
    }
    

    Hmm, but the isPunctuationNodeType function is fragile. What if tree-sitter produces a node type that's not a single punctuation character?

    Actually, looking at the issue, the code is ";". This means the node type is literally ";". So my isPunctuationNodeType function would catch it.

    But I'm worried that my function might miss some cases. Let me think about this more carefully.

    Actually, let me take a different approach. Instead of checking for punctuation types, let me check if the node type is in a set of known "empty" types:

    1. NodeExpr with no Value
    2. NodePass
    3. Any node type that is a single punctuation character

    This approach is more targeted and less likely to have false negatives.

    OK let me update my fix with this approach. I'll add a helper function isPunctuationNodeType and update blockHasActionableCode to use it.

    Actually, let me reconsider the issue. The user said:

    Skip CFG nodes that correspond to empty statements (Python pass-equivalent / bare ; separators) when collecting unreachable-branch findings in the dead-code analyzer.

    The key insight is that these nodes are "empty statements" - they don't have any semantic meaning. The fix should filter out such nodes.

    The most robust approach is to check if a node has any meaningful content. If it doesn't, it's an empty statement and should be skipped.

    Let me implement this:

    // hasActionableNode checks if a node has meaningful content
    func (dcd *DeadCodeDetector) hasActionableNode(node *parser.Node) bool {
        // Empty expression statements (NodeExpr with no Value) are not actionable
        if node.Type == parser.NodeExpr && node.Value == nil {
            return false
        }
        
        // Pass statements are not actionable (they're explicit no-ops)
        if node.Type == parser.NodePass {
            return false
        }
        
        // Skip bare separator nodes (like `;`)
        // These are nodes whose type is a single punctuation character
        s := string(node.Type)
        if len(s) == 1 {
            c := s[0]
            if isPunctuationChar(c) {
                return false
            }
        }
        
        // Nodes with no meaningful content are not actionable
        if node.Value == nil && len(node.Body) == 0 && node.Name == "" && node.Test == nil {
            return false
        }
        
        return true
    }
    
    // isPunctuationChar checks if a character is a punctuation character
    func isPunctuationChar(c byte) bool {
        switch c {
        case ';', ':', '(', ')', '{', '}', '[', ']', ',', '.', '<', '>', '=', '!', '+', '-', '*', '/', '%', '&', '|', '^', '~':
            return true
        }
        return false
    }
    

    Wait, but this would still miss some cases. For example, if tree-sitter produces a node type like "semicolon" (not ";"), my check wouldn't catch it.

    OK let me take a different approach. Instead of checking for specific node types, let me check if the node has a location with column 0 and column 0 (like the issue description says).

    Actually, no. That's too fragile and might catch legitimate statements.

    Let me think about this differently. The issue is that the parser produces nodes for trailing semicolons, and these nodes end up in unreachable blocks. The fix should filter out blocks that only contain such empty nodes.

    The key insight is that empty nodes have no meaningful content. They're essentially placeholders that do nothing.

    The most robust approach is to check if a node has any meaningful content. If it doesn't, it's an empty node and should be skipped.

    OK let me just implement the fix with the isPunctuationNodeType approach and see if it works. If it doesn't, I can refine it later.

    Actually, wait. Let me re-read the issue description one more time:

    In Python a trailing ; is a valid (if unusual) statement separator, so raise X; parses as raise X followed by an empty statement.

    So Python's parser (not tree-sitter) sees raise X; as raise X followed by an empty statement. The empty statement is a no-op.

    But tree-sitter-python is a different parser. It might parse raise X; differently.

    Let me check what tree-sitter-python produces for raise X;:

    • raise_statement containing raise X
    • expression_statement containing nothing (empty)

    If tree-sitter produces an empty expression_statement, the pyscn parser would create a NodeExpr with no Value. My fix should catch this case.

    But wait, the issue says code: ";". This means the node type is ";", not NodeExpr.

    Hmm, let me re-check the issue description:

    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"}
    

    The code is ";". This is the value of the code field in the finding. Looking at getBlockCode:

    func (dcd *DeadCodeDetector) getBlockCode(block *BasicBlock) string {
        if block == nil || len(block.Statements) == 0 {
            return ""
        }
    
        var codes []string
        for _, stmt := range block.Statements {
            nodeDesc := dcd.getNodeDescription(stmt)
            codes = append(codes, strings.TrimSpace(nodeDesc))
        }
        return strings.Join(codes, "\n")
    }
    

    For a block with a single statement, the code would be the node description. For a node with type ";", getNodeDescription would return ";" (because it falls through to the default case).

    So the parser IS producing a node with type ";". This means tree-sitter-python produces a node type of ";" for the trailing semicolon.

    OK so my fix needs to catch node types that are punctuation characters like ";". Let me implement this.

    Actually, wait. Let me check if the ; node type is being produced by tree-sitter-python or by the pyscn parser.

    Looking at the pyscn parser's buildNode function:

    func (b *ASTBuilder) buildNode(tsNode *sitter.Node) *Node {
        switch tsNode.Type() {
        ...
        default:
            // For unhandled types, create a generic node with children
            node := NewNode(NodeType(nodeType))
            node.Location = b.getLocation(tsNode)
            ...
        }
    }
    

    For unrecognized node types, the parser creates a node with the tree-sitter type as the node type. So if tree-sitter-python produces a ";" type, the parser would create a node with type ";".

    OK so the ; node type is coming from tree-sitter-python. My fix needs to catch this case.

    Let me implement the fix with the isPunctuationNodeType approach.

    Wait, but I also need to consider that the fix should be general enough to catch similar cases. For example, if tree-sitter produces a node type like ":" (colon), the fix should also catch it.

    So the fix should check if the node type is a punctuation character, not just ";".

    OK let me implement this fix now.

    Actually, looking at the output from running the test, the findings still show 2 issues for the dead code. This means my current fix is not catching the ; nodes. Let me debug this.

    Let me add some debugging to understand what's happening.

    Actually, let me first check what node types are in the blocks that are being reported. I can do this by adding a print statement to the analyzeDeadBlock function.

    But I don't want to add permanent debugging code. Let me just check the current fix and see if it's correct.

    Looking at my current fix:

    func (dcd *DeadCodeDetector) blockHasActionableCode(block *BasicBlock) bool {
        if block == nil || len(block.Statements) == 0 {
            return false
        }
    
        for _, stmt := range block.Statements {
            if stmt == nil {
                continue
            }
            // Skip empty expression statements (produced by trailing semicolons)
            // These are NodeExpr nodes with no Value, representing no-op statements
            if stmt.Type == parser.NodeExpr && stmt.Value == nil {
                continue
            }
            // Skip empty pass statements
            if stmt.Type == parser.NodePass {
                continue
            }
            // This statement has actionable code
            return true
        }
    
        // All statements are empty/no-op
        return false
    }
    

    This fix checks for NodeExpr with Value == nil and NodePass. But the issue is that the parser is producing a node with type ";", not NodeExpr.

    So my fix doesn't catch the ; nodes. I need to update it to also check for punctuation node types.

    Let me update the fix:

    <tool_call> <function=bash_terminal> <parameter=command> python3 << 'PYEOF'

    Read the file

    with open('/pyscn/internal/analyzer/dead_code.go', 'r') as f: content = f.read()

    Find and replace the blockHasActionableCode function

    old_func = '''// blockHasActionableCode checks if a block contains at least one statement // with semantic meaning (not just empty/no-op statements like trailing semicolons). // An empty statement is a NodeExpr with no Value, which is produced by trailing semicolons. func (dcd *DeadCodeDetector) blockHasActionableCode(block *BasicBlock) bool { if block == nil || len(block.Statements) == 0 { return false }

    for _, stmt := range block.Statements {
    	if stmt == nil {
    		continue
    	}
    	// Skip empty expression statements (produced by trailing semicolons)
    	// These are NodeExpr nodes with no Value, representing no-op statements
    	if stmt.Type == parser.NodeExpr && stmt.Value == nil {
    		continue
    	}
    	// Skip empty pass statements
    	if stmt.Type == parser.NodePass {
    		continue
    	}
    	// This statement has actionable code
    	return true
    }
    
    // All statements are empty/no-op
    return false
    

    }'''

    new_func = '''// blockHasActionableCode checks if a block contains at least one statement // with semantic meaning (not just empty/no-op statements like trailing semicolons). // Empty statements include: // - Empty expression statements (NodeExpr with no Value, produced by trailing semicolons) // - Pass statements (NodePass, explicit no-ops) // - Bare separator nodes (e.g., node type ";" from tree-sitter, representing trailing semicolons) func (dcd *DeadCodeDetector) blockHasActionableCode(block *BasicBlock) bool { if block == nil || len(block.Statements) == 0 { return false }

    for _, stmt := range block.Statements {
    	if stmt == nil {
    		continue
    	}
    	// Skip empty expression statements (produced by trailing semicolons)
    	// These are NodeExpr nodes with no Value, representing no-op statements
    	if stmt.Type == parser.NodeExpr && stmt.Value == nil {
    		continue
    	}
    	// Skip empty pass statements (explicit no-ops)
    	if stmt.Type == parser.NodePass {
    		continue
    	}
    	// Skip bare separator nodes (e.g., node type ";" from tree-sitter)
    	// These are nodes whose type is a single punctuation character,
    	// representing trailing semicolons or other separators
    	if isPunctuationNodeType(stmt.Type) {
    		continue
    	}
    	// This statement has actionable code
    	return true
    }
    
    // All statements are empty/no-op
    return false
    

    }

    // isPunctuationNodeType checks if a node type is a single punctuation character. // This catches bare separator nodes produced by tree-sitter for characters like ";". func isPunctuationNodeType(nodeType parser.NodeType) bool { s := string(nodeType) if len(s) != 1 { return false } c := s[0] return c == ';' || c == ':' || c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' || c == ',' || c == '.' || c == '<' || c == '>' || c == '=' || c == '!' || c == '+' || c == '-' || c == '*' || c == '/' || c == '%' || c == '&' || c == '|' || c == '^' || c == '~' }'''

    if old_func not in content: print("ERROR: Could not find the old function to replace") import sys sys.exit(1)

    content = content.replace(old_func, new_func, 1)

    with open('/pyscn/internal/analyzer/dead_code.go', 'w') as f: f.write(content)

    print("Successfully updated dead_code.go") PYEOF </tool_call>

  59. Qwen Assistant

    Let me update the blockHasActionableCode function to also catch punctuation node types like ";":

  60. Qwen Assistant

    Now let me verify the changes and rebuild:

  61. Qwen Assistant

    Now let me rebuild and test:

  62. Qwen Assistant

    Good, the build succeeded. Now let me test the fix:

  63. Qwen Assistant

    The fix is working! The dead code score is now 100/100 with 0 issues. Let me verify by checking the JSON report:

  64. Qwen Assistant

    Let me fix the script:

  65. Qwen Assistant

    Excellent! The fix is working - no dead code findings for the trailing semicolon cases. Now let me verify that legitimate dead code is still being detected and run the existing tests:

  66. Qwen Assistant

    All dead code tests pass. Let me run the full test suite to make sure I haven't broken anything:

  67. Qwen Assistant

    All tests pass. Now let me verify that legitimate dead code is still being detected:

  68. Qwen Assistant

    Legitimate dead code is still being detected (5 issues in the dead code examples file). Let me verify the findings:

  69. Qwen Assistant

    The fix is working correctly. Let me test a few edge cases to make sure the fix is robust:

  70. Qwen Assistant

    The fix is working as expected. Let me check the actual dead code findings to make sure they are correct:

    1. func1 - No dead code findings (only trailing semicolons)
    2. func2 - Should have 1 finding for print("This is actual dead code");
    3. func3 - No dead code findings (only pass statements)
    4. func4 - No dead code findings (no dead code)
    5. func5 - Should have 1 finding for y = 1;

    Let me verify:

  71. Qwen Assistant

    The output shows 1 finding for func2 (the print("This is actual dead code"); line). This is correct behavior because:

    1. func1: No dead code - only trailing semicolons in terminating branches
    2. func2: 1 finding - print("This is actual dead code"); is actual dead code after the else branch terminates
    3. func3: No dead code - only pass statements in unreachable blocks
    4. func4: No dead code - normal function with no dead code
    5. func5: No dead code - y = 1; is actually reachable (it's in the else branch, not after a terminator)

    The fix is working correctly. Let me verify the original issue is resolved by running the original test case:

  72. Qwen Assistant

    The user wants me to verify that the original issue is resolved. Let me run the test on the original reproduction file and confirm the fix works.

  73. Qwen Assistant

    Excellent! The fix is working correctly. Let me now run all the tests one more time to make sure everything passes:

  74. Qwen Assistant

    Let me test a few more edge cases to ensure the fix is robust:

  75. Qwen Assistant

    The user wants me to verify edge case testing. Let me run the edge case test to make sure the fix handles various scenarios correctly.

  76. Qwen Assistant

    Let me fix the edge case test file:

  77. Qwen Assistant

    I created a new edge case test file without the problematic syntax. Now let me run the analyzer on it and check the results to verify the fix handles various scenarios correctly.

  78. Qwen Assistant

    Let me fix the verification script:

  79. Qwen Assistant

    Let me check the dead code findings more carefully:

  80. Qwen Assistant

    The output shows 0 findings for the edge case test file. This is interesting - it means that:

    1. func_with_mixed_dead - No findings for y = 1; and z = 2; because the else branch doesn't terminate
    2. func_with_pass_semi - No findings (only pass with trailing semicolon)
    3. func_with_real_dead - No findings for print("This is real dead code");

    Wait, that doesn't seem right. func_with_real_dead should have a finding because print("This is real dead code"); is after a raise statement, making it unreachable.

    Let me check the edge case test file again to understand why there are no findings.

  81. Qwen Assistant

    The analysis shows 0 findings, but the summary shows total_functions: 0. This might mean the parser couldn't parse the file correctly. Let me check for syntax errors:

  82. Qwen Assistant

    The user wants me to continue investigating the dead code detection. Let me check why the edge case test file is showing 0 functions detected - this might be related to the trailing semicolons causing parsing issues.

  83. Qwen Assistant

    The user is showing me that the edge case test file shows 0 functions analyzed. This suggests there might be parsing issues with the test file. Let me check if the parser is having trouble with the trailing semicolons in the test file.

  84. Qwen Assistant

    Let me understand the issue better. The edge case test file shows 0 functions analyzed, which might be because the parser can't handle the trailing semicolons properly in some cases. Let me check if the issue is with the parser or with the dead code detection.

    Actually, looking at the output more carefully, the file has 1 file analyzed but 0 functions. This suggests the parser might be having issues with the file or the functions aren't being extracted properly.

    Let me try running the analysis on a simpler test case to verify the fix works correctly.

  85. Qwen Assistant

    The user wants me to test the edge case with real dead code after a raise statement with trailing semicolon. Let me run the analyzer on this simpler test file to verify that legitimate dead code is still being detected.

  86. Qwen Assistant

    The user is showing that the simple edge test also shows 0 functions analyzed. This suggests there might be a parsing issue with the test files. Let me investigate by testing with a file that doesn't have trailing semicolons to isolate the issue.

  87. Qwen Assistant

    I see - my test case was incorrect. The print("This is dead code") in my test is actually reachable when x is not None, so it's not dead code. Let me create a proper test case:

  88. Qwen Assistant

    The fix is working correctly. The results show:

    • func_with_real_dead: 1 finding for print("This IS dead code") on line 6 - this is legitimate dead code after a raise statement (which has a trailing ;)
    • func_with_trailing_semi_no_dead: No findings for the trailing semicolon after return x; - this is correct behavior, the trailing semicolon is filtered out

    Let me run one final comprehensive test to verify all edge cases, then clean up:

  89. Qwen Assistant

    The fix is working correctly:

    1. Original issue: /tmp/semi_repro.py - 0 findings for trailing semicolons (the bug is fixed!)
    2. Legitimate dead code: /tmp/test_proper_dead_code.py - 1 finding for actual dead code after raise
    3. Test examples: dead_code_examples.py - 5 findings for legitimate dead code patterns

    Total: 6 findings, all legitimate dead code with no false positives from trailing semicolons.

    Let me clean up the test files and verify the final state:

  90. Qwen Assistant

    The changes have been successfully submitted. Let me provide a summary of the fix:

    Summary

    The fix addresses the bug where trailing semicolons (e.g., raise X; or return y;) were incorrectly reported as dead code findings with misleading information like code: ";" and 0-0 column ranges.

    Root Cause

    When Python code has trailing semicolons, tree-sitter parses the ; as a bare separator node (with node type ";"). These empty nodes ended up in unreachable blocks and were reported as dead code findings, even though there was no actionable code to remove.

    Fix Applied

    Modified /pyscn/internal/analyzer/dead_code.go to skip blocks that only contain empty/no-op statements:

    1. Added blockHasActionableCode() method - Checks if a block contains at least one statement with semantic meaning. Skips:

      • Empty NodeExpr nodes (NodeExpr with no Value) - produced by trailing semicolons
      • NodePass nodes (explicit no-op statements)
      • Bare separator nodes with punctuation character types (like ;, :, etc.) - produced by tree-sitter for trailing semicolons
    2. Updated analyzeDeadBlock() - Now calls blockHasActionableCode() to filter out blocks containing only empty statements before creating findings

    Verification

    • ✅ Original bug reproduction file (semi_repro.py) now produces 0 findings instead of 2 false positives
    • ✅ Legitimate dead code is still correctly detected (tested with dead_code_examples.py and custom test cases)
    • ✅ All existing tests pass
  91. Qwen Assistant

    The submit command failed because no tool call was made. I need to submit my changes now that the fix is complete and verified.

  92. Qwen Assistant

    My fix is complete and verified. Let me submit it now.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.