# Sema: implement coerce_result_ptr for optionals · gitcafe/zig

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

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

Visibility: public

Requested revision: cb785b9c6ba705fcb507fdfa470e27b5e82ce1c5

Requested commit: cb785b9c6ba705fcb507fdfa470e27b5e82ce1c5

Commit: cb785b9c6ba705fcb507fdfa470e27b5e82ce1c5

Tree: 59bd1aa803f9669ba434aa7e7890c8c5cd283055

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
Sema: implement coerce_result_ptr for optionals

New AIR instruction: `optional_payload_ptr_set`
It's like `optional_payload_ptr` except it sets the non-null bit.

When storing to the payload via a result location that is an optional,
`optional_payload_ptr_set` is now emitted. There is a new algorithm in
`zirCoerceResultPtr` which stores a dummy value through the result
pointer into a temporary block, and then pops off the AIR instructions
from the temporary block in order to determine how to transform the
result location pointer in case any in-between coercions need to happen.

Fixes a couple of behavior tests regarding optionals.

```

## Parents

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

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