# stage2: Fix codegen for unions and error unions · gitcafe/zig

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

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

Visibility: public

Requested revision: 23e2368ac339842b907ccc36580c3a471bb26d43

Requested commit: 23e2368ac339842b907ccc36580c3a471bb26d43

Commit: 23e2368ac339842b907ccc36580c3a471bb26d43

Tree: 1522a9e220c037f9a019335b212e1901e6801102

Author: Luuk de Gram

Committer: Luuk de Gram

## Message

```
stage2: Fix codegen for unions and error unions

When an union had a zero-sized payload type, we would lower the tag twice. This is fixed
by exiting early when `payload_size` is 0.

With regards to error unions, we were only accounting for padding for the payload field.
However, the errorset value can have a smaller alignment than the payload as well, i.e. error!usize.
We fix this by also accounting for padding/alignment of the error set tag of an error union.

```

## Parents

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

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