Sema: fix single-range switch prong capture

This kind of capture cannot always be comptime-known, assuming so caused
access of undefined memory during payload capture analysis!
This commit is contained in:
Justus Klausecker 2026-01-11 20:02:27 +01:00
parent 76dd39d531
commit e2338edb47
2 changed files with 32 additions and 20 deletions

View file

@ -1307,3 +1307,18 @@ test "single-item prong in switch on enum has comptime-known capture" {
try E.doTheTest(.a);
try comptime E.doTheTest(.a);
}
test "single-range switch prong capture" {
const S = struct {
fn doTheTest(x: u8) !void {
switch (x) {
1...5 => |val| {
try expect(val == 2);
},
else => return error.TestFailed,
}
}
};
try S.doTheTest(2);
try comptime S.doTheTest(2);
}