Skip to content

Conversation

Rexicon226
Copy link
Contributor

@Rexicon226 Rexicon226 commented Oct 4, 2025

fixes: #24789 (by disallowing it)
also fixes another bug that I noticed, which remains allowed but Actually Works now.

Previously Zig allowed you to write something like,

switch (x) {
    .y => |_| {

This seems a bit strange because in other cases, such as when capturing the tag in a switch case,

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,

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.

To be clear, this PR does not remove the ability to do,

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combining labeled switch and inline switch prongs leads to compile error

1 participant