zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit f90637d5c1cdf50bdc9ee330d382a6098fa69c97 (tree)
parent 2faf8debf18f6be1f8627a69aca0bfe0d5a736fb
Author: Chadwain Holness <chadwainholness@gmail.com>
Date:   Thu, 28 May 2026 07:32:38 -0400

fix error note memory leak

Diffstat:
Mlib/std/zon/parse.zig | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/lib/std/zon/parse.zig b/lib/std/zon/parse.zig @@ -1094,6 +1094,7 @@ const Parser = struct { name: []const u8, ) error{ OutOfMemory, ParseZon } { @branchHint(.cold); + if (self.diag == null) return error.ParseZon; const gpa = self.gpa; const token = if (field) |f| b: { var buf: [2]Ast.Node.Index = undefined; @@ -1150,6 +1151,7 @@ const Parser = struct { field: usize, ) error{ OutOfMemory, ParseZon } { @branchHint(.cold); + if (self.diag == null) return error.ParseZon; const ast_node = node.getAstNode(self.zoir); var buf: [2]Ast.Node.Index = undefined; const token = if (self.ast.fullStructInit(&buf, ast_node)) |struct_init| b: { @@ -3540,3 +3542,26 @@ test "std.zon no alloc" { try fromZoirNode(Nested, ast, zoir, .root, null, .{}), ); } + +test "std.zon errors without diagnostics" { + const gpa = std.testing.allocator; + + const Enum = enum { + foo, + bar, + baz, + }; + try std.testing.expectError(error.ParseZon, fromSliceAlloc(Enum, gpa, ".nothing", null, .{})); + + const Struct = struct { + name: []const u8, + }; + try std.testing.expectError(error.ParseZon, fromSliceAlloc(Struct, gpa, ".{ .name = \"Alice\", .age = 25 }", null, .{})); + + const Union = union(enum) { + x, + y: u32, + }; + try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".a", null, .{})); + try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".{ .b = 8 }", null, .{})); +}