Skip to content

Pattern match bindings not accessible inside case block #33

@mjm918

Description

@mjm918

Description

When pattern matching an enum variant with data, the bound variable is not accessible inside the case block.

Steps to Reproduce

struct Node {
    value: int,
    next: option<Node>
}

fn main() {
    var n2: Node = Node { value: 2, next: none };
    var n1: Node = Node { value: 1, next: some(n2) };
    
    switch (n1.next) {
        case Some(n): {
            println("{}", n.value);  // ERROR: undefined variable 'n'
        }
        default: {
            println("none");
        }
    }
}

Expected: Prints 2
Actual: undefined variable 'n' at ...

Notes

The binding n from case Some(n) is recognized during parsing but not properly defined as a variable in scope during type checking or codegen, preventing field access on it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions