AstGen: error on unused switch label

This commit is contained in:
mlugg 2024-08-31 00:40:59 +01:00
parent b7a55cd6c3
commit 2b9af9e825
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E
2 changed files with 11 additions and 0 deletions

View File

@ -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);

View File

@ -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