authorgravatar for chadwainholness@gmail.comChadwain Holness <chadwainholness@gmail.com> 2026-05-28 07:32:38-04:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-05-29 00:32:15+02:00
logf90637d5c1cdf50bdc9ee330d382a6098fa69c97
treed8bc37c46fec16fdea06085122b085affbfe2fc9
parent2faf8debf18f6be1f8627a69aca0bfe0d5a736fb

fix error note memory leak


1 files changed, 25 insertions(+), 0 deletions(-)

lib/std/zon/parse.zig+25
......@@ -1094,6 +1094,7 @@ const Parser = struct {
10941094 name: []const u8,
10951095 ) error{ OutOfMemory, ParseZon } {
10961096 @branchHint(.cold);
1097 if (self.diag == null) return error.ParseZon;
10971098 const gpa = self.gpa;
10981099 const token = if (field) |f| b: {
10991100 var buf: [2]Ast.Node.Index = undefined;
......@@ -1150,6 +1151,7 @@ const Parser = struct {
11501151 field: usize,
11511152 ) error{ OutOfMemory, ParseZon } {
11521153 @branchHint(.cold);
1154 if (self.diag == null) return error.ParseZon;
11531155 const ast_node = node.getAstNode(self.zoir);
11541156 var buf: [2]Ast.Node.Index = undefined;
11551157 const token = if (self.ast.fullStructInit(&buf, ast_node)) |struct_init| b: {
......@@ -3540,3 +3542,26 @@ test "std.zon no alloc" {
35403542 try fromZoirNode(Nested, ast, zoir, .root, null, .{}),
35413543 );
35423544}
3545
3546test "std.zon errors without diagnostics" {
3547 const gpa = std.testing.allocator;
3548
3549 const Enum = enum {
3550 foo,
3551 bar,
3552 baz,
3553 };
3554 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Enum, gpa, ".nothing", null, .{}));
3555
3556 const Struct = struct {
3557 name: []const u8,
3558 };
3559 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Struct, gpa, ".{ .name = \"Alice\", .age = 25 }", null, .{}));
3560
3561 const Union = union(enum) {
3562 x,
3563 y: u32,
3564 };
3565 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".a", null, .{}));
3566 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".{ .b = 8 }", null, .{}));
3567}