# V4002 unreachable_arm

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

> A match arm can never be reached because earlier arms already cover every value it matches.

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

A `match` arm can never be reached because earlier arms already cover every value it matches.
Remove it, or move it before the arm that shadows it.

Wrong:

```sakura
match o { _ => 0, Some(n) => n }
```

Fixed:

```sakura
match o { Some(n) => n, _ => 0 }
```

## Wrong program [#wrong-program]

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

```sakura
fn sign(n: Int) -> String {
  match n {
    0 => "zero",
    _ => "nonzero",
    1 => "one",
  }
}
```

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

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:96fe8174deffcb7c",
  "code": "V4002",
  "severity": "error",
  "phase": "pattern",
  "message": "this arm is unreachable: earlier arms already match every value it matches",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V4002_unreachable_arm::sign",
  "spans": [
    {
      "uri": "file://$DIR/V4002_unreachable_arm.sakura",
      "content_hash": "sha256:863e370cf52c6eff741e6b056bc563e6a4bcd6add4c015ebadd53620de317889",
      "start_byte": 115,
      "end_byte": 116,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V4002",
  "fixes": []
}
```

## Fixed program [#fixed-program]

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

```sakura
fn sign(n: Int) -> String {
  match n {
    0 => "zero",
    1 => "one",
    _ => "other",
  }
}
```
