authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-31 00:40:59+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-09-01 18:31:01+01:00
log2b9af9e825fcbfd55f953e7c3bc80decb52a4b2b
treefcb27173da478ec2bdbb412b3d75cccb93bfeab6
parentb7a55cd6c3ca0c4c97f266b72f741b980416456a
signature Commit is signed but in an unrecognized format.

AstGen: error on unused switch label


2 files changed, 11 insertions(+), 0 deletions(-)

lib/std/zig/AstGen.zig+5
......@@ -7999,6 +7999,11 @@ fn switchExpr(
79997999 appendBodyWithFixupsArrayList(astgen, payloads, case_slice);
80008000 }
80018001 }
8002
8003 if (switch_full.label_token) |label_token| if (!block_scope.label.?.used) {
8004 try astgen.appendErrorTok(label_token, "unused switch label", .{});
8005 };
8006
80028007 // Now that the item expressions are generated we can add this.
80038008 try parent_gz.instructions.append(gpa, switch_block);
80048009
test/cases/compile_errors/duplicate-unused_labels.zig+6
......@@ -22,6 +22,11 @@ comptime {
2222comptime {
2323 blk: for (@as([0]void, undefined)) |_| {}
2424}
25comptime {
26 blk: switch (true) {
27 else => {},
28 }
29}
2530
2631// error
2732// target=native
......@@ -35,3 +40,4 @@ comptime {
3540// :17:5: error: unused block label
3641// :20:5: error: unused while loop label
3742// :23:5: error: unused for loop label
43// :26:5: error: unused switch label