Commit 2b9af9e825
Changed files (2)
lib
std
zig
test
cases
compile_errors
lib/std/zig/AstGen.zig
@@ -7999,6 +7999,11 @@ fn switchExpr(
appendBodyWithFixupsArrayList(astgen, payloads, case_slice);
}
}
+
+ if (switch_full.label_token) |label_token| if (!block_scope.label.?.used) {
+ try astgen.appendErrorTok(label_token, "unused switch label", .{});
+ };
+
// Now that the item expressions are generated we can add this.
try parent_gz.instructions.append(gpa, switch_block);
test/cases/compile_errors/duplicate-unused_labels.zig
@@ -22,6 +22,11 @@ comptime {
comptime {
blk: for (@as([0]void, undefined)) |_| {}
}
+comptime {
+ blk: switch (true) {
+ else => {},
+ }
+}
// error
// target=native
@@ -35,3 +40,4 @@ comptime {
// :17:5: error: unused block label
// :20:5: error: unused while loop label
// :23:5: error: unused for loop label
+// :26:5: error: unused switch label