# disallow switch case capture discards · gitcafe/zig

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

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

Visibility: public

Requested revision: aa2b178029fc466f847c0cb663c3b32c7809a357

Requested commit: aa2b178029fc466f847c0cb663c3b32c7809a357

Commit: aa2b178029fc466f847c0cb663c3b32c7809a357

Tree: e8f6a3b8b6b2416aef0476ce67fdceb998ad8f00

Author: David Rubin

Committer: Matthew Lugg

## Message

````
disallow switch case capture discards

Previously Zig allowed you to write something like,
```zig
switch (x) {
    .y => |_| {
```

This seems a bit strange because in other cases, such as when
capturing the tag in a switch case,
```zig
switch (x) {
    .y => |_, _| {
```
this produces an error.

The only usecase I can think of for the previous behaviour is
if you wanted to assert that all union payloads are able
to coerce,
```zig
const X = union(enum) { y: u8, z: f32 };

switch (x) {
    .y, .z => |_| {
```

This will compile-error with the `|_|` and pass without it.

I don't believe this usecase is strong enough to keep the current
behaviour; it was never used in the Zig codebase and I cannot
find a single usage of this behaviour in the real world, searching
through Sourcegraph.

````

## Parents

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

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