mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:24:49 +01:00
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:
parent
76dd39d531
commit
e2338edb47
2 changed files with 32 additions and 20 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue