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 {...@@ -1094,6 +1094,7 @@ const Parser = struct {
1094 name: []const u8,1094 name: []const u8,
1095 ) error{ OutOfMemory, ParseZon } {1095 ) error{ OutOfMemory, ParseZon } {
1096 @branchHint(.cold);1096 @branchHint(.cold);
1097 if (self.diag == null) return error.ParseZon;
1097 const gpa = self.gpa;1098 const gpa = self.gpa;
1098 const token = if (field) |f| b: {1099 const token = if (field) |f| b: {
1099 var buf: [2]Ast.Node.Index = undefined;1100 var buf: [2]Ast.Node.Index = undefined;
...@@ -1150,6 +1151,7 @@ const Parser = struct {...@@ -1150,6 +1151,7 @@ const Parser = struct {
1150 field: usize,1151 field: usize,
1151 ) error{ OutOfMemory, ParseZon } {1152 ) error{ OutOfMemory, ParseZon } {
1152 @branchHint(.cold);1153 @branchHint(.cold);
1154 if (self.diag == null) return error.ParseZon;
1153 const ast_node = node.getAstNode(self.zoir);1155 const ast_node = node.getAstNode(self.zoir);
1154 var buf: [2]Ast.Node.Index = undefined;1156 var buf: [2]Ast.Node.Index = undefined;
1155 const token = if (self.ast.fullStructInit(&buf, ast_node)) |struct_init| b: {1157 const token = if (self.ast.fullStructInit(&buf, ast_node)) |struct_init| b: {
...@@ -3540,3 +3542,26 @@ test "std.zon no alloc" {...@@ -3540,3 +3542,26 @@ test "std.zon no alloc" {
3540 try fromZoirNode(Nested, ast, zoir, .root, null, .{}),3542 try fromZoirNode(Nested, ast, zoir, .root, null, .{}),
3541 );3543 );
3542}3544}
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}