astgen: generate correct switch prong indices
Switch prong values are fetched by index in semantic analysis by prong offset, but these were computed as capture offset. This means that a switch where the first prong does not capture and the second does, the switch_capture zir instruction would be assigned switch_prong 0 instead of 1.
This commit is contained in:
committed by
Andrew Kelley
parent
17e46a3b97
commit
25012ab3d1
@@ -299,3 +299,17 @@ fn testSwitchHandleAllCasesRange(x: u8) u8 {
|
||||
204...255 => 3,
|
||||
};
|
||||
}
|
||||
|
||||
test "switch on union with some prongs capturing" {
|
||||
const X = union(enum) {
|
||||
a,
|
||||
b: i32,
|
||||
};
|
||||
|
||||
var x: X = X{ .b = 10 };
|
||||
var y: i32 = switch (x) {
|
||||
.a => unreachable,
|
||||
.b => |b| b + 1,
|
||||
};
|
||||
try expect(y == 11);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user