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

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

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

Visibility: public

Requested revision: 6ce84409875e92d69da1fd88409e2f00d4adee9f

Requested commit: 6ce84409875e92d69da1fd88409e2f00d4adee9f

Commit: 6ce84409875e92d69da1fd88409e2f00d4adee9f

Tree: 023c203932be96ed0040d6b869f03f28f8194214

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

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

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