# AstGen: properly generate errdefer expressions when returning · gitcafe/zig

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

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

Visibility: public

Requested revision: 1fe0142d1f40a0051c6a41c12640db443f635ec8

Requested commit: 1fe0142d1f40a0051c6a41c12640db443f635ec8

Commit: 1fe0142d1f40a0051c6a41c12640db443f635ec8

Tree: c3ec24dabd5d5f312ac7bd053cf0f41185d3dda8

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
AstGen: properly generate errdefer expressions when returning

`return` statements use a new function `nodeMayEvalToError` which does
some basic checks on the AST node to return never, always, or maybe.

Depending on this result, AstGen skips the errdefers, always includes
the errdefers, or emits a conditional branch to check whether the return
value is an error that Sema will have to evaluate.

Closes #8821
Unblocks #9047

```

## Parents

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

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