# AstGen: properly restore previous state after temporary changes · gitcafe/zig

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

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

Visibility: public

Requested revision: 3f5ca3920a58d44a018ff2a2e277e60813e20d5a

Requested commit: 3f5ca3920a58d44a018ff2a2e277e60813e20d5a

Commit: 3f5ca3920a58d44a018ff2a2e277e60813e20d5a

Tree: ff156147167ab13852411e5b2e9a6eed51ab88d0

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
AstGen: properly restore previous state after temporary changes

Before this, if a compile error occurred, it would cause the previous
value for e.g. the function scope to not get reset. If the AstGen
process continued, it would result in a violation of the data
guarantees that it relies on.

This commit takes advantage of defer to ensure the previous value is
always reset, even in the case of an error.

Closes #8920

```

## Parents

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

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