# Sema: implement switch expressions · gitcafe/zig

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

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

Visibility: public

Requested revision: 195ddab2be938c1201767909d39106cdf99fd07e

Requested commit: 195ddab2be938c1201767909d39106cdf99fd07e

Commit: 195ddab2be938c1201767909d39106cdf99fd07e

Tree: a24f32c4829370474b2319c9bbdd3478974d1bad

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
Sema: implement switch expressions

The logic for putting ranges into the else prong is moved from AstGen to
Sema. However, logic to emit multi-items the same as single-items cannot
be done until TZIR supports mapping multiple items to the same block of
code. This will be simple to represent when we do the upcoming TZIR memory
layout changes.

Not yet implemented in this commit is the validation of duplicate
values. The trick is going to be emitting error messages with accurate
source locations, without adding extra source nodes to the ZIR
switch instruction.

This will be done by computing the respective AST node based on the
switch node (which we do have available), only when a compile error
occurs and we need to know the source location to attach the message to.

```

## Parents

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

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