---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/irrefutable_case_pattern.py
---
## AST

```
Module(
    ModModule {
        node_index: AtomicNodeIndex(..),
        range: 0..317,
        body: [
            Match(
                StmtMatch {
                    node_index: AtomicNodeIndex(..),
                    range: 0..61,
                    subject: Name(
                        ExprName {
                            node_index: AtomicNodeIndex(..),
                            range: 6..7,
                            id: Name("x"),
                            ctx: Load,
                        },
                    ),
                    cases: [
                        MatchCase {
                            range: 13..26,
                            node_index: AtomicNodeIndex(..),
                            pattern: MatchAs(
                                PatternMatchAs {
                                    range: 18..21,
                                    node_index: AtomicNodeIndex(..),
                                    pattern: None,
                                    name: Some(
                                        Identifier {
                                            id: Name("var"),
                                            range: 18..21,
                                            node_index: AtomicNodeIndex(..),
                                        },
                                    ),
                                },
                            ),
                            guard: None,
                            body: [
                                Expr(
                                    StmtExpr {
                                        node_index: AtomicNodeIndex(..),
                                        range: 23..26,
                                        value: EllipsisLiteral(
                                            ExprEllipsisLiteral {
                                                node_index: AtomicNodeIndex(..),
                                                range: 23..26,
                                            },
                                        ),
                                    },
                                ),
                            ],
                        },
                        MatchCase {
                            range: 50..61,
                            node_index: AtomicNodeIndex(..),
                            pattern: MatchValue(
                                PatternMatchValue {
                                    range: 55..56,
                                    node_index: AtomicNodeIndex(..),
                                    value: NumberLiteral(
                                        ExprNumberLiteral {
                                            node_index: AtomicNodeIndex(..),
                                            range: 55..56,
                                            value: Int(
                                                2,
                                            ),
                                        },
                                    ),
                                },
                            ),
                            guard: None,
                            body: [
                                Expr(
                                    StmtExpr {
                                        node_index: AtomicNodeIndex(..),
                                        range: 58..61,
                                        value: EllipsisLiteral(
                                            ExprEllipsisLiteral {
                                                node_index: AtomicNodeIndex(..),
                                                range: 58..61,
                                            },
                                        ),
                                    },
                                ),
                            ],
                        },
                    ],
                },
            ),
            Match(
                StmtMatch {
                    node_index: AtomicNodeIndex(..),
                    range: 62..102,
                    subject: Name(
                        ExprName {
                            node_index: AtomicNodeIndex(..),
                            range: 68..69,
                            id: Name("x"),
                            ctx: Load,
                        },
                    ),
                    cases: [
                        MatchCase {
                            range: 75..86,
                            node_index: AtomicNodeIndex(..),
                            pattern: MatchAs(
                                PatternMatchAs {
                                    range: 80..81,
                                    node_index: AtomicNodeIndex(..),
                                    pattern: None,
                                    name: None,
                                },
                            ),
                            guard: None,
                            body: [
                                Expr(
                                    StmtExpr {
                                        node_index: AtomicNodeIndex(..),
                                        range: 83..86,
                                        value: EllipsisLiteral(
                                            ExprEllipsisLiteral {
                                                node_index: AtomicNodeIndex(..),
                                                range: 83..86,
                                            },
                                        ),
                                    },
                                ),
                            ],
                        },
                        MatchCase {
                            range: 91..102,
                            node_index: AtomicNodeIndex(..),
                            pattern: MatchValue(
                                PatternMatchValue {
                                    range: 96..97,
                                    node_index: AtomicNodeIndex(..),
                                    value: NumberLiteral(
                                        ExprNumberLiteral {
                                            node_index: AtomicNodeIndex(..),
                                            range: 96..97,
                                            value: Int(
                                                2,
                                            ),
                                        },
                                    ),
                                },
                            ),
                            guard: None,
                            body: [
                                Expr(
                                    StmtExpr {
                                        node_index: AtomicNodeIndex(..),
                                        range: 99..102,
                                        value: EllipsisLiteral(
                                            ExprEllipsisLiteral {
                                                node_index: AtomicNodeIndex(..),
                                                range: 99..102,
                                            },
                                        ),
                                    },
                                ),
                            ],
                        },
                    ],
                },
            ),
            Match(
                StmtMatch {
                    node_index: AtomicNodeIndex(..),
                    range: 125..222,
                    subject: Name(
                        ExprName {
                            node_index: AtomicNodeIndex(..),
                            range: 131..132,
                            id: Name("x"),
                            ctx: Load,
                        },
                    ),
                    cases: [
                        MatchCase {
                            range: 138..160,
                            node_index: AtomicNodeIndex(..),
                            pattern: MatchAs(
                                PatternMatchAs {
                                    range: 143..155,
                                    node_index: AtomicNodeIndex(..),
                                    pattern: Some(
                                        MatchAs(
                                            PatternMatchAs {
                                                range: 143..147,
                                                node_index: AtomicNodeIndex(..),
                                                pattern: None,
                                                name: Some(
                                                    Identifier {
                                                        id: Name("var1"),
                                                        range: 143..147,
                                                        node_index: AtomicNodeIndex(..),
                                                    },
                                                ),
                                            },
                                        ),
                                    ),
                                    name: Some(
                                        Identifier {
                                            id: Name("var2"),
                                            range: 151..155,
                                            node_index: AtomicNodeIndex(..),
                                        },
                                    ),
                                },
                            ),
                            guard: None,
                            body: [
                                Expr(
                                    StmtExpr {
                                        node_index: AtomicNodeIndex(..),
                                        range: 157..160,
                                        value: EllipsisLiteral(
                                            ExprEllipsisLiteral {
                                                node_index: AtomicNodeIndex(..),
                                                range: 157..160,
                                            },
                                        ),
                                    },
                                ),
                            ],
                        },
                        MatchCase {
                            range: 211..222,
                            node_index: AtomicNodeIndex(..),
                            pattern: MatchValue(
                                PatternMatchValue {
                                    range: 216..217,
                                    node_index: AtomicNodeIndex(..),
                                    value: NumberLiteral(
                                        ExprNumberLiteral {
                                            node_index: AtomicNodeIndex(..),
                                            range: 216..217,
                                            value: Int(
                                                2,
                                            ),
                                        },
                                    ),
                                },
                            ),
                            guard: None,
                            body: [
                                Expr(
                                    StmtExpr {
                                        node_index: AtomicNodeIndex(..),
                                        range: 219..222,
                                        value: EllipsisLiteral(
                                            ExprEllipsisLiteral {
                                                node_index: AtomicNodeIndex(..),
                                                range: 219..222,
                                            },
                                        ),
                                    },
                                ),
                            ],
                        },
                    ],
                },
            ),
            Match(
                StmtMatch {
                    node_index: AtomicNodeIndex(..),
                    range: 223..316,
                    subject: Name(
                        ExprName {
                            node_index: AtomicNodeIndex(..),
                            range: 229..230,
                            id: Name("x"),
                            ctx: Load,
                        },
                    ),
                    cases: [
                        MatchCase {
                            range: 236..264,
                            node_index: AtomicNodeIndex(..),
                            pattern: MatchOr(
                                PatternMatchOr {
                                    range: 241..259,
                                    node_index: AtomicNodeIndex(..),
                                    patterns: [
                                        MatchValue(
                                            PatternMatchValue {
                                                range: 241..253,
                                                node_index: AtomicNodeIndex(..),
                                                value: Attribute(
                                                    ExprAttribute {
                                                        node_index: AtomicNodeIndex(..),
                                                        range: 241..253,
                                                        value: Name(
                                                            ExprName {
                                                                node_index: AtomicNodeIndex(..),
                                                                range: 241..245,
                                                                id: Name("enum"),
                                                                ctx: Load,
                                                            },
                                                        ),
                                                        attr: Identifier {
                                                            id: Name("variant"),
                                                            range: 246..253,
                                                            node_index: AtomicNodeIndex(..),
                                                        },
                                                        ctx: Load,
                                                    },
                                                ),
                                            },
                                        ),
                                        MatchAs(
                                            PatternMatchAs {
                                                range: 256..259,
                                                node_index: AtomicNodeIndex(..),
                                                pattern: None,
                                                name: Some(
                                                    Identifier {
                                                        id: Name("var"),
                                                        range: 256..259,
                                                        node_index: AtomicNodeIndex(..),
                                                    },
                                                ),
                                            },
                                        ),
                                    ],
                                },
                            ),
                            guard: None,
                            body: [
                                Expr(
                                    StmtExpr {
                                        node_index: AtomicNodeIndex(..),
                                        range: 261..264,
                                        value: EllipsisLiteral(
                                            ExprEllipsisLiteral {
                                                node_index: AtomicNodeIndex(..),
                                                range: 261..264,
                                            },
                                        ),
                                    },
                                ),
                            ],
                        },
                        MatchCase {
                            range: 305..316,
                            node_index: AtomicNodeIndex(..),
                            pattern: MatchValue(
                                PatternMatchValue {
                                    range: 310..311,
                                    node_index: AtomicNodeIndex(..),
                                    value: NumberLiteral(
                                        ExprNumberLiteral {
                                            node_index: AtomicNodeIndex(..),
                                            range: 310..311,
                                            value: Int(
                                                2,
                                            ),
                                        },
                                    ),
                                },
                            ),
                            guard: None,
                            body: [
                                Expr(
                                    StmtExpr {
                                        node_index: AtomicNodeIndex(..),
                                        range: 313..316,
                                        value: EllipsisLiteral(
                                            ExprEllipsisLiteral {
                                                node_index: AtomicNodeIndex(..),
                                                range: 313..316,
                                            },
                                        ),
                                    },
                                ),
                            ],
                        },
                    ],
                },
            ),
        ],
    },
)
```
## Semantic Syntax Errors

  |
1 | match x:
2 |     case var: ...  # capture pattern
  |          ^^^ Syntax Error: name capture `var` makes remaining patterns unreachable
3 |     case 2: ...
4 | match x:
  |


  |
3 |     case 2: ...
4 | match x:
5 |     case _: ...
  |          ^ Syntax Error: wildcard makes remaining patterns unreachable
6 |     case 2: ...    # wildcard pattern
7 | match x:
  |


   |
 6 |     case 2: ...    # wildcard pattern
 7 | match x:
 8 |     case var1 as var2: ...  # as pattern with irrefutable left-hand side
   |          ^^^^ Syntax Error: name capture `var1` makes remaining patterns unreachable
 9 |     case 2: ...
10 | match x:
   |


   |
 9 |     case 2: ...
10 | match x:
11 |     case enum.variant | var: ...  # or pattern with irrefutable part
   |                         ^^^ Syntax Error: name capture `var` makes remaining patterns unreachable
12 |     case 2: ...
   |
