diff options
| author | Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com> | 2023-11-27 15:35:29 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-27 12:35:29 +0000 |
| commit | 7fbbeae617ad9c30605a78377888c284e5d9ccdc (patch) | |
| tree | 3e56b1535d3930ff7cb621630c64008ceb42261d | |
| parent | 89572c63424eb8d9da90f2676b55c660ece57688 (diff) | |
| download | zig-7fbbeae617ad9c30605a78377888c284e5d9ccdc.tar.gz zig-7fbbeae617ad9c30605a78377888c284e5d9ccdc.zip | |
value: handle lazy_align and lazy_size in writeToPackedMemory
| -rw-r--r-- | src/value.zig | 9 | ||||
| -rw-r--r-- | test/behavior/enum.zig | 10 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/value.zig b/src/value.zig index f046b9ae3d..45f603ed2d 100644 --- a/src/value.zig +++ b/src/value.zig @@ -803,7 +803,14 @@ pub const Value = struct { switch (ip.indexToKey((try val.intFromEnum(ty, mod)).toIntern()).int.storage) { inline .u64, .i64 => |int| std.mem.writeVarPackedInt(buffer, bit_offset, bits, int, endian), .big_int => |bigint| bigint.writePackedTwosComplement(buffer, bit_offset, bits, endian), - else => unreachable, + .lazy_align => |lazy_align| { + const num = Type.fromInterned(lazy_align).abiAlignment(mod).toByteUnits(0); + std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian); + }, + .lazy_size => |lazy_size| { + const num = Type.fromInterned(lazy_size).abiSize(mod); + std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian); + }, } }, .Float => switch (ty.floatBits(target)) { diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig index d203476afc..6c111c3751 100644 --- a/test/behavior/enum.zig +++ b/test/behavior/enum.zig @@ -1225,3 +1225,13 @@ test "auto-numbered enum with signed tag type" { try std.testing.expectEqualStrings("a", @tagName(E.a)); try std.testing.expectEqualStrings("b", @tagName(E.b)); } + +test "lazy initialized field" { + try std.testing.expectEqual(@as(u8, @alignOf(struct {})), getLazyInitialized(.a)); +} + +fn getLazyInitialized(param: enum(u8) { + a = @bitCast(packed struct(u8) { a: u8 }{ .a = @alignOf(struct {}) }), +}) u8 { + return @intFromEnum(param); +} |
