# stage2: fix if expressions on error unions · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/5c8bd443d92c6306f60857720103ae46ca7b8b3e)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 5c8bd443d92c6306f60857720103ae46ca7b8b3e

Requested commit: 5c8bd443d92c6306f60857720103ae46ca7b8b3e

Commit: 5c8bd443d92c6306f60857720103ae46ca7b8b3e

Tree: fbac6bd8a6d337ef035b07ef766b3718f91e0781

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: fix if expressions on error unions

AstGen had the then-else logic backwards for if expressions
on error unions. This commit fixes it.

Turns out AstGen only really needs `is_non_null` and `is_non_err`,
and does not need the `is_null` or `is_err` variants. So I removed the
`is_null{,_ptr}` and `is_err{,_ptr}` ZIR instructions (-4) and
added `is_non_err`, `is_non_err_ptr` ZIR instructions (+2) for
a total of (-2) ZIR instructions, giving us a tiny bit more headroom
within the 256 tag limit. This required swapping the order of
then/else blocks in a handful of cases, but ultimately means the
ZIR will be in the same as source order, which is convenient
when debugging.

AIR code on the other hand, gains the `is_non_err` and `is_non_err_ptr`
instructions.

Sema: fix logic in zirErrUnionCode and zirErrUnionCodePtr returning the
wrong result type.

```

## Parents

- [5816997ae79c6025d5f85aab0c9ab456fecadec9](https://git.cafe/gitcafe/zig/commit/5816997ae79c6025d5f85aab0c9ab456fecadec9?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/5c8bd443d92c6306f60857720103ae46ca7b8b3e?format=markdown)
