authorgravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-07-16 20:18:39-07:00
committergravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-09-26 12:35:37-07:00
loga4433d88b0a05b64a536a242d5d51d3371477e52
tree5add2544d5294fc293a7d41b3f7bd5802e287fd4
parent9a810ff16e1969b7be4a3e0799741fda0077b2f7

Fix parsing into align pointers


1 files changed, 29 insertions(+), 2 deletions(-)

lib/std/zon/parse.zig+29-2
......@@ -518,8 +518,13 @@ const Parser = struct {
518518 .@"enum" => return self.parseEnumLiteral(T, node),
519519 .pointer => |pointer| switch (pointer.size) {
520520 .one => {
521 const result = try self.gpa.create(pointer.child);
522 errdefer self.gpa.destroy(result);
521 const slice = try self.gpa.alignedAlloc(
522 pointer.child,
523 if (pointer.attrs.@"align") |a| .fromByteUnits(a) else null,
524 1,
525 );
526 errdefer self.gpa.free(slice);
527 const result = &slice[0];
523528 result.* = try self.parseExprInner(pointer.child, node);
524529 return result;
525530 },
......@@ -3568,3 +3573,25 @@ test "std.zon errors without diagnostics" {
35683573 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".a", null, .{}));
35693574 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".{ .b = 8 }", null, .{}));
35703575}
3576
3577test "std.zon aligned pointers" {
3578 const gpa = std.testing.allocator;
3579
3580 const n: u8 align(8) = 10;
3581 const Foo = struct {
3582 inner: *align(8) const u8,
3583 };
3584
3585 const expected: Foo = .{
3586 .inner = &n,
3587 };
3588 const found = try fromSliceAlloc(
3589 Foo,
3590 gpa,
3591 ".{ .inner = 10 }",
3592 null,
3593 .{},
3594 );
3595 defer free(gpa, found);
3596 try std.testing.expectEqualDeep(expected.inner, found.inner);
3597}