V1012 mixed_union_alternatives
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:
error Timeout
type Outcome = Timeout | DoneFixed:
error Timeout
type Outcome = Expired | DoneWrong program
compiler/tests/ui/V1012_mixed_union_alternatives.sakura, which the compiler's ui suite runs through sakura check:
error Timeout
type Outcome = Timeout | Donesakura check --json reports this record (pretty-printed; $DIR is the fixture's directory):
{
"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
compiler/tests/ui/V1012_mixed_union_alternatives.fixed.sakura, which sakura check accepts with no diagnostics:
error Timeout
type Outcome = Expired | Done