# V4003 or_pattern_bindings

URL: /docs/errors/V4003
Markdown: /docs/errors/V4003.md

> All alternatives of an or-pattern must bind the same names with the same types (design §3.2).

An error from the `pattern` phase. `sakura explain V4003` prints this explanation offline.

All alternatives of an or-pattern must bind the same names with the same types (design §3.2).
Bind the name in every alternative, replace it with `_`, or split the alternatives into arms.

Wrong:

```sakura
(x, 0) | (0, _) => 1
```

Fixed:

```sakura
(_, 0) | (0, _) => 1
```

## Wrong program [#wrong-program]

[`compiler/tests/ui/V4003_or_pattern_bindings.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V4003_or_pattern_bindings.sakura), which the compiler's ui suite runs through `sakura check`:

```sakura
fn pick(p: (Int, Int)) -> Int {
  match p {
    (x, 0) | (0, _) => 1,
    _ => 0,
  }
}
```

`sakura check --json` reports this record (pretty-printed; `$DIR` is the fixture's directory):

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:a98f0035700d955c",
  "code": "V4003",
  "severity": "error",
  "phase": "pattern",
  "message": "alternatives of an or-pattern must bind the same names: the first binds {x}, this one binds {}",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V4003_or_pattern_bindings::pick",
  "spans": [
    {
      "uri": "file://$DIR/V4003_or_pattern_bindings.sakura",
      "content_hash": "sha256:5a1c45ebaa3fce59725ab156882795b3723d76bb541d0b4ad9bf11715c24b8b4",
      "start_byte": 91,
      "end_byte": 97,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V4003",
  "fixes": []
}
```

## Fixed program [#fixed-program]

[`compiler/tests/ui/V4003_or_pattern_bindings.fixed.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V4003_or_pattern_bindings.fixed.sakura), which `sakura check` accepts with no diagnostics:

```sakura
fn pick(p: (Int, Int)) -> Int {
  match p {
    (_, 0) | (0, _) => 1,
    _ => 0,
  }
}
```
