| author | |
| committer | |
| log | 79eade752f576ed3d0fd1cf1c9866b27e048ba6d |
| tree | d12c1b794e8c8442f035d42d321f6037b4991ef0 |
| parent | b23c07ee6dbee16e5fd3601fcef67aee22bdd348 |
| signature | Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM |
This reverts commit 5382c84ed22519a600642f5cf3b1d8c2769050d6.
Caused breaking changes; should not have been backported.4 files changed, 4 insertions(+), 23 deletions(-)
lib/std/zig/AstGen.zig-6| ... | @@ -7731,12 +7731,6 @@ fn switchExpr( | ... | @@ -7731,12 +7731,6 @@ fn switchExpr( |
| 7731 | const tag_name = try astgen.identAsString(tag_token); | 7731 | const tag_name = try astgen.identAsString(tag_token); |
| 7732 | try astgen.detectLocalShadowing(payload_sub_scope, tag_name, tag_token, tag_slice, .@"switch tag capture"); | 7732 | try astgen.detectLocalShadowing(payload_sub_scope, tag_name, tag_token, tag_slice, .@"switch tag capture"); |
| 7733 | 7733 | ||
| 7734 | if (case_node.toOptional() == else_case_node and case.inline_token == null) { | ||
| 7735 | return astgen.failTokNotes(tag_token, "cannot capture tag of 'else' prong", .{}, &.{ | ||
| 7736 | try astgen.errNoteTok(ident, "first capture in 'else' prong always captures 'switch' operand", .{}), | ||
| 7737 | }); | ||
| 7738 | } | ||
| 7739 | |||
| 7740 | assert(any_has_tag_capture); | 7734 | assert(any_has_tag_capture); |
| 7741 | has_tag_capture = true; | 7735 | has_tag_capture = true; |
| 7742 | 7736 |
test/behavior/switch.zig+2-1| ... | @@ -1186,7 +1186,8 @@ test "switch with tag capture" { | ... | @@ -1186,7 +1186,8 @@ test "switch with tag capture" { |
| 1186 | _ = &tag; | 1186 | _ = &tag; |
| 1187 | comptime unreachable; | 1187 | comptime unreachable; |
| 1188 | }, | 1188 | }, |
| 1189 | else => |un| { | 1189 | else => |un, tag| { |
| 1190 | try expect(tag == .c); | ||
| 1190 | try expect(un == .c); | 1191 | try expect(un == .c); |
| 1191 | try expect(un.c == 0xFF); | 1192 | try expect(un.c == 0xFF); |
| 1192 | }, | 1193 | }, |
test/behavior/switch_loop.zig+2-1| ... | @@ -416,7 +416,8 @@ test "switch loop with tag capture" { | ... | @@ -416,7 +416,8 @@ test "switch loop with tag capture" { |
| 416 | _ = &tag; | 416 | _ = &tag; |
| 417 | return error.AnalyzedNoreturnProng; | 417 | return error.AnalyzedNoreturnProng; |
| 418 | }, | 418 | }, |
| 419 | else => |un| { | 419 | else => |un, tag| { |
| 420 | try expect(tag == .c); | ||
| 420 | try expect(un == .c); | 421 | try expect(un == .c); |
| 421 | if (un.c == 0xFF) continue :label .a; | 422 | if (un.c == 0xFF) continue :label .a; |
| 422 | if (un.c == 0x00) break :label false; | 423 | if (un.c == 0x00) break :label false; |
test/cases/compile_errors/tag_capture_in_else_prong.zig deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | const Foo = union(enum) { a: u32, b: u32 }; | ||
| 2 | export fn entry() void { | ||
| 3 | const foo: Foo = .{ .a = 123 }; | ||
| 4 | switch (foo) { | ||
| 5 | else => |payload, tag| { | ||
| 6 | _ = payload; | ||
| 7 | _ = tag; | ||
| 8 | }, | ||
| 9 | } | ||
| 10 | } | ||
| 11 | |||
| 12 | // error | ||
| 13 | // | ||
| 14 | // :5:27: error: cannot capture tag of 'else' prong | ||
| 15 | // :5:18: note: first capture in 'else' prong always captures 'switch' operand | ||