# AstGen: fix loop result locations · gitcafe/zig

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

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

Visibility: public

Requested revision: 70894d5c2f6032b0d0be1fa00a30554b7e6db2d6

Requested commit: 70894d5c2f6032b0d0be1fa00a30554b7e6db2d6

Commit: 70894d5c2f6032b0d0be1fa00a30554b7e6db2d6

Tree: f54e4c5757e41dd1add4aa61ff60a6e6923087d6

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
AstGen: fix loop result locations

The main problem was that the loop body was treated as an expression
that was one of the peer result values of a loop, when in reality the
loop body is noreturn and only the `break` operands are the result
values of loops.

This was solved by introducing an override that prevents rvalue() from
emitting a store to result location instruction for loop bodies.

An orthogonal change also included in this commit is switching
`elem_val` index expressions to using `coerced_ty` and doing the
coercion to `usize` inside `Sema`, resulting in smaller ZIR (since the
cast becomes implied).

I also changed the break operand expression to use `reachableExpr`,
introducing a new compile error for double break.

This makes a few more behavior tests pass for `while` and `for` loops.

```

## Parents

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

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