# wasm: Implement optionals · gitcafe/zig

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

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

Visibility: public

Requested revision: 61de59e121ebd5ad2a8af871ddb1d785c3694481

Requested commit: 61de59e121ebd5ad2a8af871ddb1d785c3694481

Commit: 61de59e121ebd5ad2a8af871ddb1d785c3694481

Tree: 3faaf644c970ce194adfd77be0778d8939852d6a

Author: Luuk de Gram

Committer: Luuk de Gram

## Message

```
wasm: Implement optionals

This uses the same approach as error unions,
meaning it's a `WValue` with its tag set to `multi_value`.
The initial index of the multi_value will contain the null-tag, used to check if the value
is null or not. The other values will be the payload.

To support the `.?` shorthand syntax, we save the result from checking the null-tag
into a new local, which can then be loaded later in the block to either hit `unreachable` or
set the actual payload value.

Currently, it seems `.?` and `orelse unreachable` results in different AIR structure.
TODO: Is this expected?

```

## Parents

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

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