# stage2: fix switch on tagged union capture-by-pointer · gitcafe/zig

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

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

Visibility: public

Requested revision: 8509e7111d80a07e778aa2a57d58d2bea6945014

Requested commit: 8509e7111d80a07e778aa2a57d58d2bea6945014

Commit: 8509e7111d80a07e778aa2a57d58d2bea6945014

Tree: e7eedaf980ada713a6c3d2da3e6153751d03bed6

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: fix switch on tagged union capture-by-pointer

 * AstGen: always use `typeof` and never `typeof_elem` on the
   `switch_cond`/`switch_cond_ref` instruction because both variants
   return a value and not a pointer.
   - Delete the `typeof_elem` ZIR instruction since it is no longer
     needed.
 * Sema: validateUnionInit now recognizes a comptime mutable value and
   no longer emits a compile error saying "cannot evaluate constant
   expression"
   - Still to-do is detecting comptime union values in a function that
     is not being executed at compile-time.
     - This is still to-do for structs too.
 * Sema: when emitting a call AIR instruction, call resolveTypeLayout on
   all the parameter types as well as the return type.
 * `Type.structFieldOffset` now works for unions in addition to structs.

```

## Parents

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

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