# stage2: error return tracing handles ret better · gitcafe/zig

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

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

Visibility: public

Requested revision: 3389890709b8470c59cadc21471e4a6c8dda48a6

Requested commit: 3389890709b8470c59cadc21471e4a6c8dda48a6

Commit: 3389890709b8470c59cadc21471e4a6c8dda48a6

Tree: 9819644d3770e73cf350e78a7f05fe270d86019b

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

````
stage2: error return tracing handles ret better

Sema: insert an error return trace frame when appropriate when analyzing
ret_load. Also optimize the instructions to avoid an unnecessary block
sent to the backends.

AstGen: always emit a dbg_stmt for return expressions, in between the
defer instructions and the return instruction.

This improves the following test case:

```zig
pub fn main() !void {
    return foo();
}

fn foo() !void {
    return error.Bad;
}
```

The error return trace now points to the return token instead of
pointing to the foo() function call, matching stage1.

````

## Parents

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

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