# V1012 mixed_union_alternatives

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

> type X = A | B must be either all existing error tags (an error-union alias) or all new variants.

An error from the `resolve` phase. `sakura explain V1012` prints this explanation offline.

`type X = A | B` must be either all existing error tags (an error-union alias) or all new
variants. Mixing the two is ambiguous (design §3.2). Rename the new variant so it does not reuse
an error tag's name, or declare the missing name as an `error` too.

Wrong:

```sakura
error Timeout
type Outcome = Timeout | Done
```

Fixed:

```sakura
error Timeout
type Outcome = Expired | Done
```

## Wrong program [#wrong-program]

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

```sakura
error Timeout

type Outcome = Timeout | Done
```

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

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:8eb6f8cfc13795d6",
  "code": "V1012",
  "severity": "error",
  "phase": "resolve",
  "message": "this type mixes existing error tags (Timeout) with new variants; an error union lists only error tags, a variant type declares only new variants",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V1012_mixed_union_alternatives::Outcome",
  "spans": [
    {
      "uri": "file://$DIR/V1012_mixed_union_alternatives.sakura",
      "content_hash": "sha256:950b59440e6999bac8ea41049a65b91424e9ca2f47cdd4c3547a9fcda8b3e2e7",
      "start_byte": 49,
      "end_byte": 78,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V1012",
  "fixes": []
}
```

## Fixed program [#fixed-program]

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

```sakura
error Timeout

type Outcome = Expired | Done
```
