# AstGen: emit \`as\` instructions for branching expressions · gitcafe/zig

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

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

Visibility: public

Requested revision: 7f41e20802fd8f9eb19c0218f1e2000e2751592a

Requested commit: 7f41e20802fd8f9eb19c0218f1e2000e2751592a

Commit: 7f41e20802fd8f9eb19c0218f1e2000e2751592a

Tree: 535a39fbae2c811e4c7af03b36cf52b3f164ad73

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
AstGen: emit `as` instructions for branching expressions

There is a mechanism to avoid redundant `as` ZIR instructions which is
to pass `ResultLoc.coerced_ty` instead of `ResultLoc.ty` when it is
known by AstGen that Sema will do the coercion.

This commit downgrades `coerced_ty` to `ty` when a result location
passes through an expression that branches, such as `if`, `switch`,
`while`, and `for`, causing the `as` ZIR instruction to be emitted.

This ensures that the type of a result location will be applied to, e.g.
a `comptime_int` on either side of a branch on a runtime condition.

```

## Parents

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

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