| author | |
| committer | |
| log | 2b9af9e825fcbfd55f953e7c3bc80decb52a4b2b |
| tree | fcb27173da478ec2bdbb412b3d75cccb93bfeab6 |
| parent | b7a55cd6c3ca0c4c97f266b72f741b980416456a |
| signature |
2 files changed, 11 insertions(+), 0 deletions(-)
lib/std/zig/AstGen.zig+5| ... | @@ -7999,6 +7999,11 @@ fn switchExpr( | ... | @@ -7999,6 +7999,11 @@ fn switchExpr( |
| 7999 | appendBodyWithFixupsArrayList(astgen, payloads, case_slice); | 7999 | appendBodyWithFixupsArrayList(astgen, payloads, case_slice); |
| 8000 | } | 8000 | } |
| 8001 | } | 8001 | } |
| 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 | |||
| 8002 | // Now that the item expressions are generated we can add this. | 8007 | // Now that the item expressions are generated we can add this. |
| 8003 | try parent_gz.instructions.append(gpa, switch_block); | 8008 | try parent_gz.instructions.append(gpa, switch_block); |
| 8004 | 8009 |
test/cases/compile_errors/duplicate-unused_labels.zig+6| ... | @@ -22,6 +22,11 @@ comptime { | ... | @@ -22,6 +22,11 @@ comptime { |
| 22 | comptime { | 22 | comptime { |
| 23 | blk: for (@as([0]void, undefined)) |_| {} | 23 | blk: for (@as([0]void, undefined)) |_| {} |
| 24 | } | 24 | } |
| 25 | comptime { | ||
| 26 | blk: switch (true) { | ||
| 27 | else => {}, | ||
| 28 | } | ||
| 29 | } | ||
| 25 | 30 | ||
| 26 | // error | 31 | // error |
| 27 | // target=native | 32 | // target=native |
| ... | @@ -35,3 +40,4 @@ comptime { | ... | @@ -35,3 +40,4 @@ comptime { |
| 35 | // :17:5: error: unused block label | 40 | // :17:5: error: unused block label |
| 36 | // :20:5: error: unused while loop label | 41 | // :20:5: error: unused while loop label |
| 37 | // :23:5: error: unused for loop label | 42 | // :23:5: error: unused for loop label |
| 43 | // :26:5: error: unused switch label |