| author | |
| committer | |
| log | e70a0b2a6b329a76e9edc4d22c7b923841703a24 |
| tree | b4c701e37ca21ed6e232cc35d6c381262bb87a70 |
| parent | 82133cd992575ab567091eaf2f12fbe5e326b5df |
Closes #150192 files changed, 25 insertions(+), 0 deletions(-)
src/value.zig+5| ... | ... | @@ -1113,6 +1113,10 @@ pub const Value = extern union { |
| 1113 | 1113 | .bool_true, |
| 1114 | 1114 | => return BigIntMutable.init(&space.limbs, 1).toConst(), |
| 1115 | 1115 | |
| 1116 | .enum_field_index => { | |
| 1117 | const index = val.castTag(.enum_field_index).?.data; | |
| 1118 | return BigIntMutable.init(&space.limbs, index).toConst(); | |
| 1119 | }, | |
| 1116 | 1120 | .runtime_value => { |
| 1117 | 1121 | const sub_val = val.castTag(.runtime_value).?.data; |
| 1118 | 1122 | return sub_val.toBigIntAdvanced(space, target, opt_sema); |
| ... | ... | @@ -1983,6 +1987,7 @@ pub const Value = extern union { |
| 1983 | 1987 | .variable, |
| 1984 | 1988 | => .gt, |
| 1985 | 1989 | |
| 1990 | .enum_field_index => return std.math.order(lhs.castTag(.enum_field_index).?.data, 0), | |
| 1986 | 1991 | .runtime_value => { |
| 1987 | 1992 | // This is needed to correctly handle hashing the value. |
| 1988 | 1993 | // Checks in Sema should prevent direct comparisons from reaching here. |
test/behavior/union.zig+20| ... | ... | @@ -1513,3 +1513,23 @@ test "packed union with zero-bit field" { |
| 1513 | 1513 | }; |
| 1514 | 1514 | try S.doTest(.{ .nested = .{ .zero = {} }, .bar = 42 }); |
| 1515 | 1515 | } |
| 1516 | ||
| 1517 | test "reinterpreting enum value inside packed union" { | |
| 1518 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | |
| 1519 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 1520 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 1521 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 1522 | ||
| 1523 | const U = packed union { | |
| 1524 | tag: enum { a, b }, | |
| 1525 | val: u8, | |
| 1526 | ||
| 1527 | fn doTest() !void { | |
| 1528 | var u: @This() = .{ .tag = .a }; | |
| 1529 | u.val += 1; | |
| 1530 | try expect(u.tag == .b); | |
| 1531 | } | |
| 1532 | }; | |
| 1533 | try U.doTest(); | |
| 1534 | comptime try U.doTest(); | |
| 1535 | } |