authorgravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-09-28 00:20:25-07:00
committergravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-09-28 00:30:42-07:00
log58ce0f3d913dfe0cb91dc151c40128c433f41d98
tree199838982657e2af511e034638fe6ecae47c0868
parent139666586ec5a59ff4d4e6973b857c058dc9b572

Rename `Errors` to `Diagnostics` to match other uses of this pattern in std


1 files changed, 502 insertions(+), 549 deletions(-)

lib/std/zon/parse.zig+502-549
......@@ -23,82 +23,14 @@ const ArenaAllocator = std.heap.ArenaAllocator;
2323/// Rename when adding or removing support for a type.
2424const valid_types = {};
2525
26/// An error encountered while parsing ZON.
27pub const Error = struct {
28 msg: []const u8,
29 loc: Ast.Location,
30 token: Ast.OptionalTokenIndex,
31 /// If `token == .none`, this is an `Ast.Node.Index`.
32 /// Otherwise, this is a byte offset into `token`.
33 node_or_offset: u32,
34 notes: []Note,
35
36 const Options = struct {
37 msg: []const u8,
38 token: Ast.OptionalTokenIndex,
39 node_or_offset: u32,
40 notes: []Note,
41 };
42
43 fn init(ast: *const Ast, options: Error.Options) Error {
44 return .{
45 .msg = options.msg,
46 .loc = astLoc(ast, options.token, options.node_or_offset),
47 .token = options.token,
48 .node_or_offset = options.node_or_offset,
49 .notes = options.notes,
50 };
51 }
52
53 fn astLoc(
54 ast: *const Ast,
55 maybe_token: Ast.OptionalTokenIndex,
56 node_or_offset: u32,
57 ) Ast.Location {
58 if (maybe_token.unwrap()) |token| {
59 var loc = ast.tokenLocation(0, token);
60 loc.column += node_or_offset;
61 return loc;
62 } else {
63 const ast_node: Ast.Node.Index = @fromBackingInt(@intCast(node_or_offset));
64 const token = ast.nodeMainToken(ast_node);
65 return ast.tokenLocation(0, token);
66 }
67 }
68
69 pub const Note = struct {
70 msg: []const u8,
71 loc: Ast.Location,
72 token: Ast.OptionalTokenIndex,
73 /// If `token == .none`, this is an `Ast.Node.Index`.
74 /// Otherwise, this is a byte offset into `token`.
75 node_or_offset: u32,
76
77 const Options = struct {
78 msg: []const u8,
79 token: Ast.OptionalTokenIndex,
80 node_or_offset: u32,
81 };
82
83 fn init(ast: *const Ast, options: Note.Options) @This() {
84 return .{
85 .msg = options.msg,
86 .loc = astLoc(ast, options.token, options.node_or_offset),
87 .token = options.token,
88 .node_or_offset = options.node_or_offset,
89 };
90 }
91 };
92};
93
9426/// Errors encountered while parsing ZON. See `log` and `fatal` for reporting errors to the user.
95pub const Errors = struct {
96 items: []const Error,
27pub const Diagnostics = struct {
28 errors: []const Error,
9729
98 pub const empty: Errors = .{ .items = &.{} };
30 pub const empty: Diagnostics = .{ .errors = &.{} };
9931
10032 /// Log the failure with `std.log.err`.
101 pub fn log(self: *const Errors, path: []const u8) void {
33 pub fn log(self: *const Diagnostics, path: []const u8) void {
10234 std.log.err("{f}", .{self.fmt(path)});
10335 }
10436
......@@ -107,7 +39,7 @@ pub const Errors = struct {
10739 var arena_allocator: ArenaAllocator = .init(gpa);
10840 defer arena_allocator.deinit();
10941 const arena = arena_allocator.allocator();
110 var errors: Errors = .empty;
42 var diagnostics: Diagnostics = .empty;
11143
11244 const MyType = struct {
11345 foo: u32,
......@@ -118,11 +50,11 @@ pub const Errors = struct {
11850 .gpa = gpa,
11951 .arena = arena,
12052 .source = ".{ .foo = 1, .bar = 2 }",
121 .errors = &errors,
53 .diagnostics = &diagnostics,
12254 }) catch |err| switch (err) {
12355 error.OutOfMemory => return error.OutOfMemory,
12456 error.ParseZon => b: {
125 errors.log("input.zon");
57 diagnostics.log("input.zon");
12658 break :b .{ .foo = 0, .bar = 0 };
12759 },
12860 };
......@@ -130,7 +62,7 @@ pub const Errors = struct {
13062 }
13163
13264 /// Log the failure with `std.log.err`, and then terminate the process with exit code 1.
133 pub fn fatal(self: *const Errors, path: []const u8) noreturn {
65 pub fn fatal(self: *const Diagnostics, path: []const u8) noreturn {
13466 std.process.fatal("{f}", .{self.fmt(path)});
13567 }
13668
......@@ -139,7 +71,7 @@ pub const Errors = struct {
13971 var arena_allocator: ArenaAllocator = .init(gpa);
14072 defer arena_allocator.deinit();
14173 const arena = arena_allocator.allocator();
142 var errors: Errors = .empty;
74 var diagnostics: Diagnostics = .empty;
14375
14476 const MyType = struct {
14577 foo: u32,
......@@ -150,27 +82,44 @@ pub const Errors = struct {
15082 .gpa = gpa,
15183 .arena = arena,
15284 .source = ".{ .foo = 1, .bar = 2 }",
153 .errors = &errors,
85 .diagnostics = &diagnostics,
15486 }) catch |err| switch (err) {
15587 error.OutOfMemory => return error.OutOfMemory,
156 error.ParseZon => errors.fatal("input.zon"),
88 error.ParseZon => diagnostics.fatal("input.zon"),
15789 };
15890 _ = parsed;
15991 }
16092
161 pub fn fmt(self: *const Errors, path: []const u8) Formatter {
93 /// Formats a human readable description of any errors.
94 pub fn fmt(self: *const Diagnostics, path: []const u8) Formatter {
16295 return .{
163 .items = self.items,
96 .errors = self.errors,
16497 .path = path,
16598 };
16699 }
167100
101 fn astLoc(
102 ast: *const Ast,
103 maybe_token: Ast.OptionalTokenIndex,
104 node_or_offset: u32,
105 ) Ast.Location {
106 if (maybe_token.unwrap()) |token| {
107 var loc = ast.tokenLocation(0, token);
108 loc.column += node_or_offset;
109 return loc;
110 } else {
111 const ast_node: Ast.Node.Index = @fromBackingInt(@intCast(node_or_offset));
112 const token = ast.nodeMainToken(ast_node);
113 return ast.tokenLocation(0, token);
114 }
115 }
116
168117 pub const Formatter = struct {
169118 path: []const u8,
170 items: []const Error,
119 errors: []const Error,
171120
172121 pub fn format(self: *const @This(), w: *std.Io.Writer) std.Io.Writer.Error!void {
173 for (self.items) |e| {
122 for (self.errors) |e| {
174123 try w.print("{s}:", .{self.path});
175124 try w.print("{d}:{d}: error: {s}\n", .{
176125 e.loc.line + 1,
......@@ -189,23 +138,74 @@ pub const Errors = struct {
189138 }
190139 }
191140 };
141
142 pub const Error = struct {
143 msg: []const u8,
144 loc: Ast.Location,
145 token: Ast.OptionalTokenIndex,
146 /// If `token == .none`, this is an `Ast.Node.Index`.
147 /// Otherwise, this is a byte offset into `token`.
148 node_or_offset: u32,
149 notes: []Note,
150
151 const Options = struct {
152 msg: []const u8,
153 token: Ast.OptionalTokenIndex,
154 node_or_offset: u32,
155 notes: []Note,
156 };
157
158 fn init(ast: *const Ast, options: Error.Options) Error {
159 return .{
160 .msg = options.msg,
161 .loc = astLoc(ast, options.token, options.node_or_offset),
162 .token = options.token,
163 .node_or_offset = options.node_or_offset,
164 .notes = options.notes,
165 };
166 }
167 };
168
169 pub const Note = struct {
170 msg: []const u8,
171 loc: Ast.Location,
172 token: Ast.OptionalTokenIndex,
173 /// If `token == .none`, this is an `Ast.Node.Index`.
174 /// Otherwise, this is a byte offset into `token`.
175 node_or_offset: u32,
176
177 const Options = struct {
178 msg: []const u8,
179 token: Ast.OptionalTokenIndex,
180 node_or_offset: u32,
181 };
182
183 fn init(ast: *const Ast, options: Note.Options) @This() {
184 return .{
185 .msg = options.msg,
186 .loc = astLoc(ast, options.token, options.node_or_offset),
187 .token = options.token,
188 .node_or_offset = options.node_or_offset,
189 };
190 }
191 };
192192};
193193
194194pub const Options = struct {
195195 /// Used for scratch allocations.
196196 gpa: Allocator,
197 /// Used for allocating errors and results.
197 /// Used for allocating diagnostics and results.
198198 arena: Allocator,
199199 /// The ZON source to parse.
200200 source: [:0]const u8,
201201 /// When an error is returned from the parser, a human readable error description of the failure
202202 /// is stored here.
203 errors: *Errors,
203 diagnostics: *Diagnostics,
204204 /// If true, unknown fields do not error.
205205 ignore_unknown_fields: bool = false,
206206};
207207
208/// Parses the given slice as ZON, writing any errors to `options.errors`.
208/// Parses the given slice as ZON, writing any errors to `options.diagnostics`.
209209pub fn fromSlice(T: type, options: Options) error{ OutOfMemory, ParseZon }!T {
210210 var value: T = undefined;
211211 try fromSliceInner(T, &value, false, options);
......@@ -232,16 +232,16 @@ test fromSlice {
232232 \\}
233233 ;
234234
235 var errors: Errors = .empty;
235 var diagnostics: Diagnostics = .empty;
236236 const options = fromSlice(TextureOptions, .{
237237 .gpa = gpa,
238238 .arena = arena,
239239 .source = source,
240 .errors = &errors,
240 .diagnostics = &diagnostics,
241241 }) catch |err| switch (err) {
242242 error.OutOfMemory => return err,
243243 error.ParseZon => {
244 errors.log("texture_options.zon");
244 diagnostics.log("texture_options.zon");
245245 return err;
246246 },
247247 };
......@@ -307,16 +307,16 @@ test updateFromSlice {
307307 .theme = "default",
308308 };
309309
310 var errors: Errors = .empty;
310 var diagnostics: Diagnostics = .empty;
311311 updateFromSlice(MyTextEditorConfig, &config, .{
312312 .gpa = gpa,
313313 .arena = arena,
314314 .source = global_config,
315 .errors = &errors,
315 .diagnostics = &diagnostics,
316316 }) catch |err| switch (err) {
317317 error.OutOfMemory => return err,
318318 error.ParseZon => {
319 errors.log("global_config.zon");
319 diagnostics.log("global_config.zon");
320320 return err;
321321 },
322322 };
......@@ -324,11 +324,11 @@ test updateFromSlice {
324324 .gpa = gpa,
325325 .arena = arena,
326326 .source = project_config,
327 .errors = &errors,
327 .diagnostics = &diagnostics,
328328 }) catch |err| switch (err) {
329329 error.OutOfMemory => return err,
330330 error.ParseZon => {
331 errors.log("project_config.zon");
331 diagnostics.log("project_config.zon");
332332 return err;
333333 },
334334 };
......@@ -358,8 +358,8 @@ fn fromSliceInner(
358358 initialized: bool,
359359 options: Options,
360360) error{ OutOfMemory, ParseZon }!void {
361 var errors: std.ArrayList(Error) = .empty;
362 defer options.errors.items = errors.items;
361 var errors: std.ArrayList(Diagnostics.Error) = .empty;
362 defer options.diagnostics.errors = errors.items;
363363
364364 var ast = try std.zig.Ast.parse(options.gpa, options.source, .{ .mode = .zon });
365365 defer ast.deinit(options.gpa);
......@@ -378,7 +378,7 @@ fn fromSliceInner(
378378}
379379
380380pub const FromZoirOptions = struct {
381 /// Used for allocating errors and results.
381 /// Used for allocating diagnostics and results.
382382 arena: Allocator,
383383 /// The AST for this ZON value.
384384 ast: *const Ast,
......@@ -388,7 +388,7 @@ pub const FromZoirOptions = struct {
388388 node: Zoir.Node.Index = .root,
389389 /// When an error is returned from the parser, a human readable error description of the failure
390390 /// is stored here.
391 errors: *Errors,
391 diagnostics: *Diagnostics,
392392 /// If true, unknown fields do not error.
393393 ignore_unknown_fields: bool = false,
394394};
......@@ -431,8 +431,8 @@ fn fromZoirInner(
431431 initialized: bool,
432432 options: FromZoirOptions,
433433) error{ OutOfMemory, ParseZon }!void {
434 var errors: std.ArrayList(Error) = .empty;
435 defer options.errors.items = errors.items;
434 var errors: std.ArrayList(Diagnostics.Error) = .empty;
435 defer options.diagnostics.errors = errors.items;
436436 return inner(T, value, initialized, .{
437437 .arena = options.arena,
438438 .ast = options.ast,
......@@ -447,7 +447,7 @@ const InnerOptions = struct {
447447 ast: *const Ast,
448448 zoir: *const Zoir,
449449 node: Zoir.Node.Index = .root,
450 errors: *std.ArrayList(Error),
450 errors: *std.ArrayList(Diagnostics.Error),
451451 ignore_unknown_fields: bool,
452452};
453453
......@@ -461,7 +461,7 @@ fn inner(
461461
462462 if (options.zoir.hasCompileErrors()) {
463463 for (options.zoir.compile_errors) |e| {
464 var notes: std.ArrayList(Error.Note) = .empty;
464 var notes: std.ArrayList(Diagnostics.Note) = .empty;
465465 for (e.getNotes(options.zoir)) |note| {
466466 try notes.append(options.arena, .init(options.ast, .{
467467 .msg = try options.arena.dupe(u8, note.msg.get(options.zoir)),
......@@ -515,7 +515,7 @@ const Parser = struct {
515515 arena: Allocator,
516516 ast: *const Ast,
517517 zoir: *const Zoir,
518 errors: *std.ArrayList(Error),
518 errors: *std.ArrayList(Diagnostics.Error),
519519 ignore_unknown_fields: bool,
520520
521521 const ParseExprError = error{ ParseZon, OutOfMemory };
......@@ -1086,7 +1086,7 @@ const Parser = struct {
10861086 offset: u32,
10871087 comptime fmt: []const u8,
10881088 args: anytype,
1089 notes: []Error.Note,
1089 notes: []Diagnostics.Note,
10901090 ) error{ OutOfMemory, ParseZon } {
10911091 @branchHint(.cold);
10921092 comptime assert(args.len > 0);
......@@ -1112,7 +1112,7 @@ const Parser = struct {
11121112
11131113 fn failToken(
11141114 self: Parser,
1115 failure: Error,
1115 failure: Diagnostics.Error,
11161116 ) error{ OutOfMemory, ParseZon } {
11171117 @branchHint(.cold);
11181118 try self.errors.append(self.arena, failure);
......@@ -1160,7 +1160,7 @@ const Parser = struct {
11601160 } else self.ast.nodeMainToken(node.getAstNode(self.zoir));
11611161 switch (@typeInfo(T)) {
11621162 inline .@"struct", .@"union", .@"enum" => |info| {
1163 var notes: std.ArrayList(Error.Note) = .empty;
1163 var notes: std.ArrayList(Diagnostics.Note) = .empty;
11641164 if (info.field_names.len == 0) {
11651165 try notes.append(self.arena, .init(self.ast, .{
11661166 .token = .fromToken(token),
......@@ -1384,20 +1384,20 @@ test "std.zon ast errors" {
13841384 var arena_allocator: ArenaAllocator = .init(gpa);
13851385 defer arena_allocator.deinit();
13861386 const arena = arena_allocator.allocator();
1387 var errors: Errors = .empty;
1387 var diagnostics: Diagnostics = .empty;
13881388 try std.testing.expectError(
13891389 error.ParseZon,
13901390 fromSliceNoAlloc(struct {}, .{
13911391 .gpa = gpa,
13921392 .arena = arena,
13931393 .source = ".{.x = 1 .y = 2}",
1394 .errors = &errors,
1394 .diagnostics = &diagnostics,
13951395 }),
13961396 );
13971397 try std.testing.expectFmt(
13981398 \\input.zon:1:13: error: expected ',' after initializer
13991399 \\
1400 , "{f}", .{errors.fmt("input.zon")});
1400 , "{f}", .{diagnostics.fmt("input.zon")});
14011401}
14021402
14031403test "std.zon comments" {
......@@ -1405,7 +1405,7 @@ test "std.zon comments" {
14051405 var arena_allocator: ArenaAllocator = .init(gpa);
14061406 defer arena_allocator.deinit();
14071407 const arena = arena_allocator.allocator();
1408 var errors: Errors = .empty;
1408 var diagnostics: Diagnostics = .empty;
14091409
14101410 try std.testing.expectEqual(@as(u8, 10), fromSliceNoAlloc(u8, .{
14111411 .gpa = gpa,
......@@ -1415,7 +1415,7 @@ test "std.zon comments" {
14151415 \\10 // comment
14161416 \\// comment
14171417 ,
1418 .errors = &errors,
1418 .diagnostics = &diagnostics,
14191419 }));
14201420
14211421 {
......@@ -1427,12 +1427,12 @@ test "std.zon comments" {
14271427 \\10 // comment
14281428 \\// comment
14291429 ,
1430 .errors = &errors,
1430 .diagnostics = &diagnostics,
14311431 }));
14321432 try std.testing.expectFmt(
14331433 \\input.zon:1:1: error: expected expression, found 'a document comment'
14341434 \\
1435 , "{f}", .{errors.fmt("input.zon")});
1435 , "{f}", .{diagnostics.fmt("input.zon")});
14361436 }
14371437}
14381438
......@@ -1441,17 +1441,17 @@ test "std.zon failure/oom formatting" {
14411441 var arena_allocator: ArenaAllocator = .init(gpa);
14421442 defer arena_allocator.deinit();
14431443 const arena = arena_allocator.allocator();
1444 var errors: Errors = .empty;
1444 var diagnostics: Diagnostics = .empty;
14451445
14461446 try std.testing.expectError(error.OutOfMemory, fromSlice([]const u8, .{
14471447 .gpa = .failing,
14481448 .arena = arena,
14491449 .source = "\"foo\"",
1450 .errors = &errors,
1450 .diagnostics = &diagnostics,
14511451 }));
14521452 try std.testing.expectFmt(
14531453 \\
1454 , "{f}", .{errors.fmt("input.zon")});
1454 , "{f}", .{diagnostics.fmt("input.zon")});
14551455}
14561456
14571457test "std.zon fromSlice syntax error" {
......@@ -1459,20 +1459,20 @@ test "std.zon fromSlice syntax error" {
14591459 var arena_allocator: ArenaAllocator = .init(gpa);
14601460 defer arena_allocator.deinit();
14611461 const arena = arena_allocator.allocator();
1462 var errors: Errors = .empty;
1462 var diagnostics: Diagnostics = .empty;
14631463 try std.testing.expectError(
14641464 error.ParseZon,
14651465 fromSliceNoAlloc(u8, .{
14661466 .gpa = gpa,
14671467 .arena = arena,
14681468 .source = ".{",
1469 .errors = &errors,
1469 .diagnostics = &diagnostics,
14701470 }),
14711471 );
14721472 try std.testing.expectFmt(
14731473 \\input.zon:1:3: error: expected expression, found 'EOF'
14741474 \\
1475 , "{f}", .{errors.fmt("input.zon")});
1475 , "{f}", .{diagnostics.fmt("input.zon")});
14761476}
14771477
14781478test "std.zon optional" {
......@@ -1480,7 +1480,7 @@ test "std.zon optional" {
14801480 var arena_allocator: ArenaAllocator = .init(gpa);
14811481 defer arena_allocator.deinit();
14821482 const arena = arena_allocator.allocator();
1483 var errors: Errors = .empty;
1483 var diagnostics: Diagnostics = .empty;
14841484
14851485 // Basic usage
14861486 {
......@@ -1488,14 +1488,14 @@ test "std.zon optional" {
14881488 .gpa = gpa,
14891489 .arena = arena,
14901490 .source = "null",
1491 .errors = &errors,
1491 .diagnostics = &diagnostics,
14921492 });
14931493 try std.testing.expect(none == null);
14941494 const some = try fromSliceNoAlloc(?u32, .{
14951495 .gpa = gpa,
14961496 .arena = arena,
14971497 .source = "1",
1498 .errors = &errors,
1498 .diagnostics = &diagnostics,
14991499 });
15001500 try std.testing.expect(some.? == 1);
15011501 }
......@@ -1506,14 +1506,14 @@ test "std.zon optional" {
15061506 .gpa = gpa,
15071507 .arena = arena,
15081508 .source = "null",
1509 .errors = &errors,
1509 .diagnostics = &diagnostics,
15101510 });
15111511 try std.testing.expect(none == null);
15121512 const some = try fromSlice(?[]const u8, .{
15131513 .gpa = gpa,
15141514 .arena = arena,
15151515 .source = "\"foo\"",
1516 .errors = &errors,
1516 .diagnostics = &diagnostics,
15171517 });
15181518 try std.testing.expectEqualStrings("foo", some.?);
15191519 }
......@@ -1524,7 +1524,7 @@ test "std.zon unions" {
15241524 var arena_allocator: ArenaAllocator = .init(gpa);
15251525 defer arena_allocator.deinit();
15261526 const arena = arena_allocator.allocator();
1527 var errors: Errors = .empty;
1527 var diagnostics: Diagnostics = .empty;
15281528
15291529 // Unions
15301530 {
......@@ -1535,28 +1535,28 @@ test "std.zon unions" {
15351535 .gpa = gpa,
15361536 .arena = arena,
15371537 .source = ".{.x = 1.5}",
1538 .errors = &errors,
1538 .diagnostics = &diagnostics,
15391539 });
15401540 try std.testing.expectEqual(Tagged{ .x = 1.5 }, tagged_x);
15411541 const tagged_y = try fromSliceNoAlloc(Tagged, .{
15421542 .gpa = gpa,
15431543 .arena = arena,
15441544 .source = ".{.@\"y y\" = true}",
1545 .errors = &errors,
1545 .diagnostics = &diagnostics,
15461546 });
15471547 try std.testing.expectEqual(Tagged{ .@"y y" = true }, tagged_y);
15481548 const tagged_z_shorthand = try fromSliceNoAlloc(Tagged, .{
15491549 .gpa = gpa,
15501550 .arena = arena,
15511551 .source = ".z",
1552 .errors = &errors,
1552 .diagnostics = &diagnostics,
15531553 });
15541554 try std.testing.expectEqual(@as(Tagged, .z), tagged_z_shorthand);
15551555 const tagged_zz_shorthand = try fromSliceNoAlloc(Tagged, .{
15561556 .gpa = gpa,
15571557 .arena = arena,
15581558 .source = ".@\"z z\"",
1559 .errors = &errors,
1559 .diagnostics = &diagnostics,
15601560 });
15611561 try std.testing.expectEqual(@as(Tagged, .@"z z"), tagged_zz_shorthand);
15621562
......@@ -1564,14 +1564,14 @@ test "std.zon unions" {
15641564 .gpa = gpa,
15651565 .arena = arena,
15661566 .source = ".{.x = 1.5}",
1567 .errors = &errors,
1567 .diagnostics = &diagnostics,
15681568 });
15691569 try std.testing.expect(untagged_x.x == 1.5);
15701570 const untagged_y = try fromSliceNoAlloc(Untagged, .{
15711571 .gpa = gpa,
15721572 .arena = arena,
15731573 .source = ".{.@\"y y\" = true}",
1574 .errors = &errors,
1574 .diagnostics = &diagnostics,
15751575 });
15761576 try std.testing.expect(untagged_y.@"y y");
15771577 }
......@@ -1584,7 +1584,7 @@ test "std.zon unions" {
15841584 .gpa = gpa,
15851585 .arena = arena,
15861586 .source = ".{.baz = false}",
1587 .errors = &errors,
1587 .diagnostics = &diagnostics,
15881588 });
15891589 try std.testing.expectEqual(Union{ .baz = false }, noalloc);
15901590
......@@ -1592,7 +1592,7 @@ test "std.zon unions" {
15921592 .gpa = gpa,
15931593 .arena = arena,
15941594 .source = ".{.bar = \"qux\"}",
1595 .errors = &errors,
1595 .diagnostics = &diagnostics,
15961596 });
15971597 try std.testing.expectEqualDeep(Union{ .bar = "qux" }, alloc);
15981598 }
......@@ -1606,14 +1606,14 @@ test "std.zon unions" {
16061606 .gpa = gpa,
16071607 .arena = arena,
16081608 .source = ".{.z=2.5}",
1609 .errors = &errors,
1609 .diagnostics = &diagnostics,
16101610 }),
16111611 );
16121612 try std.testing.expectFmt(
16131613 \\input.zon:1:4: error: unexpected field 'z'
16141614 \\input.zon:1:4: note: supported: 'x', 'y'
16151615 \\
1616 , "{f}", .{errors.fmt("input.zon")});
1616 , "{f}", .{diagnostics.fmt("input.zon")});
16171617 }
16181618
16191619 // Explicit void field
......@@ -1625,13 +1625,13 @@ test "std.zon unions" {
16251625 .gpa = gpa,
16261626 .arena = arena,
16271627 .source = ".{.x=1}",
1628 .errors = &errors,
1628 .diagnostics = &diagnostics,
16291629 }),
16301630 );
16311631 try std.testing.expectFmt(
16321632 \\input.zon:1:6: error: expected type 'void'
16331633 \\
1634 , "{f}", .{errors.fmt("input.zon")});
1634 , "{f}", .{diagnostics.fmt("input.zon")});
16351635 }
16361636
16371637 // Extra field
......@@ -1643,13 +1643,13 @@ test "std.zon unions" {
16431643 .gpa = gpa,
16441644 .arena = arena,
16451645 .source = ".{.x = 1.5, .y = true}",
1646 .errors = &errors,
1646 .diagnostics = &diagnostics,
16471647 }),
16481648 );
16491649 try std.testing.expectFmt(
16501650 \\input.zon:1:2: error: expected union
16511651 \\
1652 , "{f}", .{errors.fmt("input.zon")});
1652 , "{f}", .{diagnostics.fmt("input.zon")});
16531653 }
16541654
16551655 // No fields
......@@ -1661,13 +1661,13 @@ test "std.zon unions" {
16611661 .gpa = gpa,
16621662 .arena = arena,
16631663 .source = ".{}",
1664 .errors = &errors,
1664 .diagnostics = &diagnostics,
16651665 }),
16661666 );
16671667 try std.testing.expectFmt(
16681668 \\input.zon:1:2: error: expected union
16691669 \\
1670 , "{f}", .{errors.fmt("input.zon")});
1670 , "{f}", .{diagnostics.fmt("input.zon")});
16711671 }
16721672
16731673 // Enum literals cannot coerce into untagged unions
......@@ -1677,12 +1677,12 @@ test "std.zon unions" {
16771677 .gpa = gpa,
16781678 .arena = arena,
16791679 .source = ".x",
1680 .errors = &errors,
1680 .diagnostics = &diagnostics,
16811681 }));
16821682 try std.testing.expectFmt(
16831683 \\input.zon:1:2: error: expected union
16841684 \\
1685 , "{f}", .{errors.fmt("input.zon")});
1685 , "{f}", .{diagnostics.fmt("input.zon")});
16861686 }
16871687
16881688 // Unknown field for enum literal coercion
......@@ -1692,13 +1692,13 @@ test "std.zon unions" {
16921692 .gpa = gpa,
16931693 .arena = arena,
16941694 .source = ".y",
1695 .errors = &errors,
1695 .diagnostics = &diagnostics,
16961696 }));
16971697 try std.testing.expectFmt(
16981698 \\input.zon:1:2: error: unexpected field 'y'
16991699 \\input.zon:1:2: note: supported: 'x'
17001700 \\
1701 , "{f}", .{errors.fmt("input.zon")});
1701 , "{f}", .{diagnostics.fmt("input.zon")});
17021702 }
17031703
17041704 // Non void field for enum literal coercion
......@@ -1708,12 +1708,12 @@ test "std.zon unions" {
17081708 .gpa = gpa,
17091709 .arena = arena,
17101710 .source = ".x",
1711 .errors = &errors,
1711 .diagnostics = &diagnostics,
17121712 }));
17131713 try std.testing.expectFmt(
17141714 \\input.zon:1:2: error: expected union
17151715 \\
1716 , "{f}", .{errors.fmt("input.zon")});
1716 , "{f}", .{diagnostics.fmt("input.zon")});
17171717 }
17181718}
17191719
......@@ -1722,7 +1722,7 @@ test "std.zon structs" {
17221722 var arena_allocator: ArenaAllocator = .init(gpa);
17231723 defer arena_allocator.deinit();
17241724 const arena = arena_allocator.allocator();
1725 var errors: Errors = .empty;
1725 var diagnostics: Diagnostics = .empty;
17261726
17271727 // Structs (various sizes tested since they're parsed differently)
17281728 {
......@@ -1735,7 +1735,7 @@ test "std.zon structs" {
17351735 .gpa = gpa,
17361736 .arena = arena,
17371737 .source = ".{}",
1738 .errors = &errors,
1738 .diagnostics = &diagnostics,
17391739 });
17401740 try std.testing.expectEqual(Vec0{}, zero);
17411741
......@@ -1743,7 +1743,7 @@ test "std.zon structs" {
17431743 .gpa = gpa,
17441744 .arena = arena,
17451745 .source = ".{.x = 1.2}",
1746 .errors = &errors,
1746 .diagnostics = &diagnostics,
17471747 });
17481748 try std.testing.expectEqual(Vec1{ .x = 1.2 }, one);
17491749
......@@ -1751,7 +1751,7 @@ test "std.zon structs" {
17511751 .gpa = gpa,
17521752 .arena = arena,
17531753 .source = ".{.x = 1.2, .y = 3.4}",
1754 .errors = &errors,
1754 .diagnostics = &diagnostics,
17551755 });
17561756 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 3.4 }, two);
17571757
......@@ -1759,7 +1759,7 @@ test "std.zon structs" {
17591759 .gpa = gpa,
17601760 .arena = arena,
17611761 .source = ".{.x = 1.2, .y = 3.4, .z = 5.6}",
1762 .errors = &errors,
1762 .diagnostics = &diagnostics,
17631763 });
17641764 try std.testing.expectEqual(Vec3{ .x = 1.2, .y = 3.4, .z = 5.6 }, three);
17651765 }
......@@ -1772,7 +1772,7 @@ test "std.zon structs" {
17721772 .gpa = gpa,
17731773 .arena = arena,
17741774 .source = ".{.bar = \"qux\", .baz = .{\"a\", \"b\"}}",
1775 .errors = &errors,
1775 .diagnostics = &diagnostics,
17761776 });
17771777 try std.testing.expectEqualDeep(Foo{ .bar = "qux", .baz = &.{ "a", "b" } }, parsed);
17781778 }
......@@ -1786,14 +1786,14 @@ test "std.zon structs" {
17861786 .gpa = gpa,
17871787 .arena = arena,
17881788 .source = ".{.x=1.5, .z=2.5}",
1789 .errors = &errors,
1789 .diagnostics = &diagnostics,
17901790 }),
17911791 );
17921792 try std.testing.expectFmt(
17931793 \\input.zon:1:12: error: unexpected field 'z'
17941794 \\input.zon:1:12: note: supported: 'x', 'y'
17951795 \\
1796 , "{f}", .{errors.fmt("input.zon")});
1796 , "{f}", .{diagnostics.fmt("input.zon")});
17971797 }
17981798
17991799 // Duplicate field
......@@ -1805,14 +1805,14 @@ test "std.zon structs" {
18051805 .gpa = gpa,
18061806 .arena = arena,
18071807 .source = ".{.x=1.5, .x=2.5, .x=3.5}",
1808 .errors = &errors,
1808 .diagnostics = &diagnostics,
18091809 }),
18101810 );
18111811 try std.testing.expectFmt(
18121812 \\input.zon:1:4: error: duplicate struct field name
18131813 \\input.zon:1:12: note: duplicate name here
18141814 \\
1815 , "{f}", .{errors.fmt("input.zon")});
1815 , "{f}", .{diagnostics.fmt("input.zon")});
18161816 }
18171817
18181818 // Ignore unknown fields
......@@ -1823,7 +1823,7 @@ test "std.zon structs" {
18231823 .arena = arena,
18241824 .source = ".{ .x = 1.0, .z = 3.0 }",
18251825 .ignore_unknown_fields = true,
1826 .errors = &errors,
1826 .diagnostics = &diagnostics,
18271827 });
18281828 try std.testing.expectEqual(Vec2{ .x = 1.0, .y = 2.0 }, parsed);
18291829 }
......@@ -1837,14 +1837,14 @@ test "std.zon structs" {
18371837 .gpa = gpa,
18381838 .arena = arena,
18391839 .source = ".{.x=1.5, .z=2.5}",
1840 .errors = &errors,
1840 .diagnostics = &diagnostics,
18411841 }),
18421842 );
18431843 try std.testing.expectFmt(
18441844 \\input.zon:1:4: error: unexpected field 'x'
18451845 \\input.zon:1:4: note: none expected
18461846 \\
1847 , "{f}", .{errors.fmt("input.zon")});
1847 , "{f}", .{diagnostics.fmt("input.zon")});
18481848 }
18491849
18501850 // Missing field
......@@ -1856,13 +1856,13 @@ test "std.zon structs" {
18561856 .gpa = gpa,
18571857 .arena = arena,
18581858 .source = ".{.x=1.5}",
1859 .errors = &errors,
1859 .diagnostics = &diagnostics,
18601860 }),
18611861 );
18621862 try std.testing.expectFmt(
18631863 \\input.zon:1:2: error: missing required field y
18641864 \\
1865 , "{f}", .{errors.fmt("input.zon")});
1865 , "{f}", .{diagnostics.fmt("input.zon")});
18661866 }
18671867
18681868 // Default field
......@@ -1872,7 +1872,7 @@ test "std.zon structs" {
18721872 .gpa = gpa,
18731873 .arena = arena,
18741874 .source = ".{.x = 1.2}",
1875 .errors = &errors,
1875 .diagnostics = &diagnostics,
18761876 });
18771877 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed);
18781878 }
......@@ -1884,7 +1884,7 @@ test "std.zon structs" {
18841884 .gpa = gpa,
18851885 .arena = arena,
18861886 .source = ".{.x = 1.2}",
1887 .errors = &errors,
1887 .diagnostics = &diagnostics,
18881888 });
18891889 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed);
18901890 }
......@@ -1896,13 +1896,13 @@ test "std.zon structs" {
18961896 .gpa = gpa,
18971897 .arena = arena,
18981898 .source = ".{.x = 1.2, .y = 1.5}",
1899 .errors = &errors,
1899 .diagnostics = &diagnostics,
19001900 });
19011901 try std.testing.expectError(error.ParseZon, parsed);
19021902 try std.testing.expectFmt(
19031903 \\input.zon:1:18: error: cannot initialize comptime field
19041904 \\
1905 , "{f}", .{errors.fmt("input.zon")});
1905 , "{f}", .{diagnostics.fmt("input.zon")});
19061906 }
19071907
19081908 // Enum field (regression test, we were previously getting the field name in an
......@@ -1913,7 +1913,7 @@ test "std.zon structs" {
19131913 .gpa = gpa,
19141914 .arena = arena,
19151915 .source = ".{ .x = .x }",
1916 .errors = &errors,
1916 .diagnostics = &diagnostics,
19171917 });
19181918 try std.testing.expectEqual(Vec0{ .x = .x }, parsed);
19191919 }
......@@ -1925,7 +1925,7 @@ test "std.zon structs" {
19251925 .gpa = gpa,
19261926 .arena = arena,
19271927 .source = ".{ .@\"x x\" = .@\"x x\" }",
1928 .errors = &errors,
1928 .diagnostics = &diagnostics,
19291929 });
19301930 try std.testing.expectEqual(Vec0{ .@"x x" = .@"x x" }, parsed);
19311931 }
......@@ -1938,14 +1938,14 @@ test "std.zon structs" {
19381938 .gpa = gpa,
19391939 .arena = arena,
19401940 .source = "Empty{}",
1941 .errors = &errors,
1941 .diagnostics = &diagnostics,
19421942 });
19431943 try std.testing.expectError(error.ParseZon, parsed);
19441944 try std.testing.expectFmt(
19451945 \\input.zon:1:1: error: types are not available in ZON
19461946 \\input.zon:1:1: note: replace the type with '.'
19471947 \\
1948 , "{f}", .{errors.fmt("input.zon")});
1948 , "{f}", .{diagnostics.fmt("input.zon")});
19491949 }
19501950
19511951 // Arrays
......@@ -1954,14 +1954,14 @@ test "std.zon structs" {
19541954 .gpa = gpa,
19551955 .arena = arena,
19561956 .source = "[3]u8{1, 2, 3}",
1957 .errors = &errors,
1957 .diagnostics = &diagnostics,
19581958 });
19591959 try std.testing.expectError(error.ParseZon, parsed);
19601960 try std.testing.expectFmt(
19611961 \\input.zon:1:1: error: types are not available in ZON
19621962 \\input.zon:1:1: note: replace the type with '.'
19631963 \\
1964 , "{f}", .{errors.fmt("input.zon")});
1964 , "{f}", .{diagnostics.fmt("input.zon")});
19651965 }
19661966
19671967 // Slices
......@@ -1970,14 +1970,14 @@ test "std.zon structs" {
19701970 .gpa = gpa,
19711971 .arena = arena,
19721972 .source = "[]u8{1, 2, 3}",
1973 .errors = &errors,
1973 .diagnostics = &diagnostics,
19741974 });
19751975 try std.testing.expectError(error.ParseZon, parsed);
19761976 try std.testing.expectFmt(
19771977 \\input.zon:1:1: error: types are not available in ZON
19781978 \\input.zon:1:1: note: replace the type with '.'
19791979 \\
1980 , "{f}", .{errors.fmt("input.zon")});
1980 , "{f}", .{diagnostics.fmt("input.zon")});
19811981 }
19821982
19831983 // Tuples
......@@ -1986,14 +1986,14 @@ test "std.zon structs" {
19861986 .gpa = gpa,
19871987 .arena = arena,
19881988 .source = "Tuple{1, 2, 3}",
1989 .errors = &errors,
1989 .diagnostics = &diagnostics,
19901990 });
19911991 try std.testing.expectError(error.ParseZon, parsed);
19921992 try std.testing.expectFmt(
19931993 \\input.zon:1:1: error: types are not available in ZON
19941994 \\input.zon:1:1: note: replace the type with '.'
19951995 \\
1996 , "{f}", .{errors.fmt("input.zon")});
1996 , "{f}", .{diagnostics.fmt("input.zon")});
19971997 }
19981998
19991999 // Nested
......@@ -2002,14 +2002,14 @@ test "std.zon structs" {
20022002 .gpa = gpa,
20032003 .arena = arena,
20042004 .source = ".{ .x = Tuple{1, 2, 3} }",
2005 .errors = &errors,
2005 .diagnostics = &diagnostics,
20062006 });
20072007 try std.testing.expectError(error.ParseZon, parsed);
20082008 try std.testing.expectFmt(
20092009 \\input.zon:1:9: error: types are not available in ZON
20102010 \\input.zon:1:9: note: replace the type with '.'
20112011 \\
2012 , "{f}", .{errors.fmt("input.zon")});
2012 , "{f}", .{diagnostics.fmt("input.zon")});
20132013 }
20142014 }
20152015}
......@@ -2019,7 +2019,7 @@ test "std.zon tuples" {
20192019 var arena_allocator: ArenaAllocator = .init(gpa);
20202020 defer arena_allocator.deinit();
20212021 const arena = arena_allocator.allocator();
2022 var errors: Errors = .empty;
2022 var diagnostics: Diagnostics = .empty;
20232023
20242024 // Structs (various sizes tested since they're parsed differently)
20252025 {
......@@ -2032,7 +2032,7 @@ test "std.zon tuples" {
20322032 .gpa = gpa,
20332033 .arena = arena,
20342034 .source = ".{}",
2035 .errors = &errors,
2035 .diagnostics = &diagnostics,
20362036 });
20372037 try std.testing.expectEqual(Tuple0{}, zero);
20382038
......@@ -2040,7 +2040,7 @@ test "std.zon tuples" {
20402040 .gpa = gpa,
20412041 .arena = arena,
20422042 .source = ".{1.2}",
2043 .errors = &errors,
2043 .diagnostics = &diagnostics,
20442044 });
20452045 try std.testing.expectEqual(Tuple1{1.2}, one);
20462046
......@@ -2048,7 +2048,7 @@ test "std.zon tuples" {
20482048 .gpa = gpa,
20492049 .arena = arena,
20502050 .source = ".{1.2, true}",
2051 .errors = &errors,
2051 .diagnostics = &diagnostics,
20522052 });
20532053 try std.testing.expectEqual(Tuple2{ 1.2, true }, two);
20542054
......@@ -2056,7 +2056,7 @@ test "std.zon tuples" {
20562056 .gpa = gpa,
20572057 .arena = arena,
20582058 .source = ".{1.2, false, 3}",
2059 .errors = &errors,
2059 .diagnostics = &diagnostics,
20602060 });
20612061 try std.testing.expectEqual(Tuple3{ 1.2, false, 3 }, three);
20622062 }
......@@ -2068,7 +2068,7 @@ test "std.zon tuples" {
20682068 .gpa = gpa,
20692069 .arena = arena,
20702070 .source = ".{\"hello\", \"world\"}",
2071 .errors = &errors,
2071 .diagnostics = &diagnostics,
20722072 });
20732073 try std.testing.expectEqualDeep(Tuple{ "hello", "world" }, parsed);
20742074 }
......@@ -2082,13 +2082,13 @@ test "std.zon tuples" {
20822082 .gpa = gpa,
20832083 .arena = arena,
20842084 .source = ".{0.5, true, 123}",
2085 .errors = &errors,
2085 .diagnostics = &diagnostics,
20862086 }),
20872087 );
20882088 try std.testing.expectFmt(
20892089 \\input.zon:1:14: error: index 2 outside of tuple length 2
20902090 \\
2091 , "{f}", .{errors.fmt("input.zon")});
2091 , "{f}", .{diagnostics.fmt("input.zon")});
20922092 }
20932093
20942094 // Extra field
......@@ -2100,13 +2100,13 @@ test "std.zon tuples" {
21002100 .gpa = gpa,
21012101 .arena = arena,
21022102 .source = ".{0.5}",
2103 .errors = &errors,
2103 .diagnostics = &diagnostics,
21042104 }),
21052105 );
21062106 try std.testing.expectFmt(
21072107 \\input.zon:1:2: error: missing tuple field with index 1
21082108 \\
2109 , "{f}", .{errors.fmt("input.zon")});
2109 , "{f}", .{diagnostics.fmt("input.zon")});
21102110 }
21112111
21122112 // Tuple with unexpected field names
......@@ -2118,13 +2118,13 @@ test "std.zon tuples" {
21182118 .gpa = gpa,
21192119 .arena = arena,
21202120 .source = ".{.foo = 10.0}",
2121 .errors = &errors,
2121 .diagnostics = &diagnostics,
21222122 }),
21232123 );
21242124 try std.testing.expectFmt(
21252125 \\input.zon:1:2: error: expected tuple
21262126 \\
2127 , "{f}", .{errors.fmt("input.zon")});
2127 , "{f}", .{diagnostics.fmt("input.zon")});
21282128 }
21292129
21302130 // Struct with missing field names
......@@ -2136,13 +2136,13 @@ test "std.zon tuples" {
21362136 .gpa = gpa,
21372137 .arena = arena,
21382138 .source = ".{10.0}",
2139 .errors = &errors,
2139 .diagnostics = &diagnostics,
21402140 }),
21412141 );
21422142 try std.testing.expectFmt(
21432143 \\input.zon:1:2: error: expected struct
21442144 \\
2145 , "{f}", .{errors.fmt("input.zon")});
2145 , "{f}", .{diagnostics.fmt("input.zon")});
21462146 }
21472147
21482148 // Comptime field
......@@ -2152,7 +2152,7 @@ test "std.zon tuples" {
21522152 .gpa = gpa,
21532153 .arena = arena,
21542154 .source = ".{ 1.2 }",
2155 .errors = &errors,
2155 .diagnostics = &diagnostics,
21562156 });
21572157 try std.testing.expectEqual(Vec2{ 1.2, 1.5 }, parsed);
21582158 }
......@@ -2164,13 +2164,13 @@ test "std.zon tuples" {
21642164 .gpa = gpa,
21652165 .arena = arena,
21662166 .source = ".{ 1.2, 1.5}",
2167 .errors = &errors,
2167 .diagnostics = &diagnostics,
21682168 });
21692169 try std.testing.expectError(error.ParseZon, parsed);
21702170 try std.testing.expectFmt(
21712171 \\input.zon:1:9: error: cannot initialize comptime field
21722172 \\
2173 , "{f}", .{errors.fmt("input.zon")});
2173 , "{f}", .{diagnostics.fmt("input.zon")});
21742174 }
21752175}
21762176
......@@ -2180,7 +2180,7 @@ test "std.zon arrays and slices" {
21802180 var arena_allocator: ArenaAllocator = .init(gpa);
21812181 defer arena_allocator.deinit();
21822182 const arena = arena_allocator.allocator();
2183 var errors: Errors = .empty;
2183 var diagnostics: Diagnostics = .empty;
21842184
21852185 // Literals
21862186 {
......@@ -2190,7 +2190,7 @@ test "std.zon arrays and slices" {
21902190 .gpa = gpa,
21912191 .arena = arena,
21922192 .source = ".{}",
2193 .errors = &errors,
2193 .diagnostics = &diagnostics,
21942194 });
21952195 try std.testing.expectEqualSlices(u8, &@as([0]u8, .{}), &zero);
21962196
......@@ -2198,7 +2198,7 @@ test "std.zon arrays and slices" {
21982198 .gpa = gpa,
21992199 .arena = arena,
22002200 .source = ".{'a'}",
2201 .errors = &errors,
2201 .diagnostics = &diagnostics,
22022202 });
22032203 try std.testing.expectEqualSlices(u8, &@as([1]u8, .{'a'}), &one);
22042204
......@@ -2206,7 +2206,7 @@ test "std.zon arrays and slices" {
22062206 .gpa = gpa,
22072207 .arena = arena,
22082208 .source = ".{'a', 'b'}",
2209 .errors = &errors,
2209 .diagnostics = &diagnostics,
22102210 });
22112211 try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two);
22122212
......@@ -2214,7 +2214,7 @@ test "std.zon arrays and slices" {
22142214 .gpa = gpa,
22152215 .arena = arena,
22162216 .source = ".{'a', 'b',}",
2217 .errors = &errors,
2217 .diagnostics = &diagnostics,
22182218 });
22192219 try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two_comma);
22202220
......@@ -2222,7 +2222,7 @@ test "std.zon arrays and slices" {
22222222 .gpa = gpa,
22232223 .arena = arena,
22242224 .source = ".{'a', 'b', 'c'}",
2225 .errors = &errors,
2225 .diagnostics = &diagnostics,
22262226 });
22272227 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, &three);
22282228
......@@ -2230,7 +2230,7 @@ test "std.zon arrays and slices" {
22302230 .gpa = gpa,
22312231 .arena = arena,
22322232 .source = ".{'a', 'b', 'c'}",
2233 .errors = &errors,
2233 .diagnostics = &diagnostics,
22342234 });
22352235 const expected_sentinel: [3:'z']u8 = .{ 'a', 'b', 'c' };
22362236 try std.testing.expectEqualSlices(u8, &expected_sentinel, &sentinel);
......@@ -2242,7 +2242,7 @@ test "std.zon arrays and slices" {
22422242 .gpa = gpa,
22432243 .arena = arena,
22442244 .source = ".{}",
2245 .errors = &errors,
2245 .diagnostics = &diagnostics,
22462246 });
22472247 try std.testing.expectEqualSlices(u8, @as([]const u8, &.{}), zero);
22482248
......@@ -2250,7 +2250,7 @@ test "std.zon arrays and slices" {
22502250 .gpa = gpa,
22512251 .arena = arena,
22522252 .source = ".{'a'}",
2253 .errors = &errors,
2253 .diagnostics = &diagnostics,
22542254 });
22552255 try std.testing.expectEqualSlices(u8, &.{'a'}, one);
22562256
......@@ -2258,7 +2258,7 @@ test "std.zon arrays and slices" {
22582258 .gpa = gpa,
22592259 .arena = arena,
22602260 .source = ".{'a', 'b'}",
2261 .errors = &errors,
2261 .diagnostics = &diagnostics,
22622262 });
22632263 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two);
22642264
......@@ -2266,7 +2266,7 @@ test "std.zon arrays and slices" {
22662266 .gpa = gpa,
22672267 .arena = arena,
22682268 .source = ".{'a', 'b',}",
2269 .errors = &errors,
2269 .diagnostics = &diagnostics,
22702270 });
22712271 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two_comma);
22722272
......@@ -2274,7 +2274,7 @@ test "std.zon arrays and slices" {
22742274 .gpa = gpa,
22752275 .arena = arena,
22762276 .source = ".{'a', 'b', 'c'}",
2277 .errors = &errors,
2277 .diagnostics = &diagnostics,
22782278 });
22792279 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, three);
22802280
......@@ -2282,7 +2282,7 @@ test "std.zon arrays and slices" {
22822282 .gpa = gpa,
22832283 .arena = arena,
22842284 .source = ".{'a', 'b', 'c'}",
2285 .errors = &errors,
2285 .diagnostics = &diagnostics,
22862286 });
22872287 const expected_sentinel: [:'z']const u8 = &.{ 'a', 'b', 'c' };
22882288 try std.testing.expectEqualSlices(u8, expected_sentinel, sentinel);
......@@ -2297,7 +2297,7 @@ test "std.zon arrays and slices" {
22972297 .gpa = gpa,
22982298 .arena = arena,
22992299 .source = ".{\"abc\"}",
2300 .errors = &errors,
2300 .diagnostics = &diagnostics,
23012301 });
23022302 const expected: [1][]const u8 = .{"abc"};
23032303 try std.testing.expectEqualDeep(expected, parsed);
......@@ -2309,7 +2309,7 @@ test "std.zon arrays and slices" {
23092309 .gpa = gpa,
23102310 .arena = arena,
23112311 .source = ".{\"abc\"}",
2312 .errors = &errors,
2312 .diagnostics = &diagnostics,
23132313 });
23142314 const expected: []const []const u8 = &.{"abc"};
23152315 try std.testing.expectEqualDeep(expected, parsed);
......@@ -2324,7 +2324,7 @@ test "std.zon arrays and slices" {
23242324 .gpa = gpa,
23252325 .arena = arena,
23262326 .source = ".{1}",
2327 .errors = &errors,
2327 .diagnostics = &diagnostics,
23282328 });
23292329 try std.testing.expectEqual(@as(usize, 1), sentinel.len);
23302330 try std.testing.expectEqual(@as(u8, 1), sentinel[0]);
......@@ -2337,7 +2337,7 @@ test "std.zon arrays and slices" {
23372337 .gpa = gpa,
23382338 .arena = arena,
23392339 .source = ".{1}",
2340 .errors = &errors,
2340 .diagnostics = &diagnostics,
23412341 });
23422342 try std.testing.expectEqual(@as(usize, 1), sentinel.len);
23432343 try std.testing.expectEqual(@as(u8, 1), sentinel[0]);
......@@ -2353,13 +2353,13 @@ test "std.zon arrays and slices" {
23532353 .gpa = gpa,
23542354 .arena = arena,
23552355 .source = ".{'a', 'b', 'c'}",
2356 .errors = &errors,
2356 .diagnostics = &diagnostics,
23572357 }),
23582358 );
23592359 try std.testing.expectFmt(
23602360 \\input.zon:1:3: error: index 0 outside of array of length 0
23612361 \\
2362 , "{f}", .{errors.fmt("input.zon")});
2362 , "{f}", .{diagnostics.fmt("input.zon")});
23632363 }
23642364
23652365 // Expect 1 find 2
......@@ -2370,13 +2370,13 @@ test "std.zon arrays and slices" {
23702370 .gpa = gpa,
23712371 .arena = arena,
23722372 .source = ".{'a', 'b'}",
2373 .errors = &errors,
2373 .diagnostics = &diagnostics,
23742374 }),
23752375 );
23762376 try std.testing.expectFmt(
23772377 \\input.zon:1:8: error: index 1 outside of array of length 1
23782378 \\
2379 , "{f}", .{errors.fmt("input.zon")});
2379 , "{f}", .{diagnostics.fmt("input.zon")});
23802380 }
23812381
23822382 // Expect 2 find 1
......@@ -2387,13 +2387,13 @@ test "std.zon arrays and slices" {
23872387 .gpa = gpa,
23882388 .arena = arena,
23892389 .source = ".{'a'}",
2390 .errors = &errors,
2390 .diagnostics = &diagnostics,
23912391 }),
23922392 );
23932393 try std.testing.expectFmt(
23942394 \\input.zon:1:2: error: expected 2 array elements; found 1
23952395 \\
2396 , "{f}", .{errors.fmt("input.zon")});
2396 , "{f}", .{diagnostics.fmt("input.zon")});
23972397 }
23982398
23992399 // Expect 3 find 0
......@@ -2404,13 +2404,13 @@ test "std.zon arrays and slices" {
24042404 .gpa = gpa,
24052405 .arena = arena,
24062406 .source = ".{}",
2407 .errors = &errors,
2407 .diagnostics = &diagnostics,
24082408 }),
24092409 );
24102410 try std.testing.expectFmt(
24112411 \\input.zon:1:2: error: expected 3 array elements; found 0
24122412 \\
2413 , "{f}", .{errors.fmt("input.zon")});
2413 , "{f}", .{diagnostics.fmt("input.zon")});
24142414 }
24152415
24162416 // Wrong inner type
......@@ -2423,13 +2423,13 @@ test "std.zon arrays and slices" {
24232423 .gpa = gpa,
24242424 .arena = arena,
24252425 .source = ".{'a', 'b', 'c'}",
2426 .errors = &errors,
2426 .diagnostics = &diagnostics,
24272427 }),
24282428 );
24292429 try std.testing.expectFmt(
24302430 \\input.zon:1:3: error: expected type 'bool'
24312431 \\
2432 , "{f}", .{errors.fmt("input.zon")});
2432 , "{f}", .{diagnostics.fmt("input.zon")});
24332433 }
24342434
24352435 // Slice
......@@ -2440,13 +2440,13 @@ test "std.zon arrays and slices" {
24402440 .gpa = gpa,
24412441 .arena = arena,
24422442 .source = ".{'a', 'b', 'c'}",
2443 .errors = &errors,
2443 .diagnostics = &diagnostics,
24442444 }),
24452445 );
24462446 try std.testing.expectFmt(
24472447 \\input.zon:1:3: error: expected type 'bool'
24482448 \\
2449 , "{f}", .{errors.fmt("input.zon")});
2449 , "{f}", .{diagnostics.fmt("input.zon")});
24502450 }
24512451 }
24522452
......@@ -2460,25 +2460,25 @@ test "std.zon arrays and slices" {
24602460 .gpa = gpa,
24612461 .arena = arena,
24622462 .source = "'a'",
2463 .errors = &errors,
2463 .diagnostics = &diagnostics,
24642464 }),
24652465 );
24662466 try std.testing.expectFmt(
24672467 \\input.zon:1:1: error: expected array
24682468 \\
2469 , "{f}", .{errors.fmt("input.zon")});
2469 , "{f}", .{diagnostics.fmt("input.zon")});
24702470 }
24712471
24722472 // Slice
24732473 {
24742474 try std.testing.expectError(
24752475 error.ParseZon,
2476 fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "'a'", .errors = &errors }),
2476 fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "'a'", .diagnostics = &diagnostics }),
24772477 );
24782478 try std.testing.expectFmt(
24792479 \\input.zon:1:1: error: expected array
24802480 \\
2481 , "{f}", .{errors.fmt("input.zon")});
2481 , "{f}", .{diagnostics.fmt("input.zon")});
24822482 }
24832483 }
24842484
......@@ -2486,12 +2486,12 @@ test "std.zon arrays and slices" {
24862486 {
24872487 try std.testing.expectError(
24882488 error.ParseZon,
2489 fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = " &.{'a', 'b', 'c'}", .errors = &errors }),
2489 fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = " &.{'a', 'b', 'c'}", .diagnostics = &diagnostics }),
24902490 );
24912491 try std.testing.expectFmt(
24922492 \\input.zon:1:3: error: pointers are not available in ZON
24932493 \\
2494 , "{f}", .{errors.fmt("input.zon")});
2494 , "{f}", .{diagnostics.fmt("input.zon")});
24952495 }
24962496}
24972497
......@@ -2500,7 +2500,7 @@ test "std.zon string literal" {
25002500 var arena_allocator: ArenaAllocator = .init(gpa);
25012501 defer arena_allocator.deinit();
25022502 const arena = arena_allocator.allocator();
2503 var errors: Errors = .empty;
2503 var diagnostics: Diagnostics = .empty;
25042504
25052505 // Basic string literal
25062506 {
......@@ -2508,7 +2508,7 @@ test "std.zon string literal" {
25082508 .gpa = gpa,
25092509 .arena = arena,
25102510 .source = "\"abc\"",
2511 .errors = &errors,
2511 .diagnostics = &diagnostics,
25122512 });
25132513 try std.testing.expectEqualStrings(@as([]const u8, "abc"), parsed);
25142514 }
......@@ -2519,7 +2519,7 @@ test "std.zon string literal" {
25192519 .gpa = gpa,
25202520 .arena = arena,
25212521 .source = "\"ab\\nc\"",
2522 .errors = &errors,
2522 .diagnostics = &diagnostics,
25232523 });
25242524 try std.testing.expectEqualStrings(@as([]const u8, "ab\nc"), parsed);
25252525 }
......@@ -2530,7 +2530,7 @@ test "std.zon string literal" {
25302530 .gpa = gpa,
25312531 .arena = arena,
25322532 .source = "\"ab\\x00c\"",
2533 .errors = &errors,
2533 .diagnostics = &diagnostics,
25342534 });
25352535 try std.testing.expectEqualStrings(@as([]const u8, "ab\x00c"), parsed);
25362536 }
......@@ -2540,23 +2540,23 @@ test "std.zon string literal" {
25402540 {
25412541 try std.testing.expectError(
25422542 error.ParseZon,
2543 fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "\"abcd\"", .errors = &errors }),
2543 fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "\"abcd\"", .diagnostics = &diagnostics }),
25442544 );
25452545 try std.testing.expectFmt(
25462546 \\input.zon:1:1: error: expected array
25472547 \\
2548 , "{f}", .{errors.fmt("input.zon")});
2548 , "{f}", .{diagnostics.fmt("input.zon")});
25492549 }
25502550
25512551 {
25522552 try std.testing.expectError(
25532553 error.ParseZon,
2554 fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\abcd", .errors = &errors }),
2554 fromSlice([]u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\abcd", .diagnostics = &diagnostics }),
25552555 );
25562556 try std.testing.expectFmt(
25572557 \\input.zon:1:1: error: expected array
25582558 \\
2559 , "{f}", .{errors.fmt("input.zon")});
2559 , "{f}", .{diagnostics.fmt("input.zon")});
25602560 }
25612561 }
25622562
......@@ -2573,13 +2573,13 @@ test "std.zon string literal" {
25732573 .gpa = gpa,
25742574 .arena = arena,
25752575 .source = "\"abcd\"",
2576 .errors = &errors,
2576 .diagnostics = &diagnostics,
25772577 }),
25782578 );
25792579 try std.testing.expectFmt(
25802580 \\input.zon:1:1: error: expected array
25812581 \\
2582 , "{f}", .{errors.fmt("input.zon")});
2582 , "{f}", .{diagnostics.fmt("input.zon")});
25832583 }
25842584
25852585 {
......@@ -2589,13 +2589,13 @@ test "std.zon string literal" {
25892589 .gpa = gpa,
25902590 .arena = arena,
25912591 .source = "\\\\abcd",
2592 .errors = &errors,
2592 .diagnostics = &diagnostics,
25932593 }),
25942594 );
25952595 try std.testing.expectFmt(
25962596 \\input.zon:1:1: error: expected array
25972597 \\
2598 , "{f}", .{errors.fmt("input.zon")});
2598 , "{f}", .{diagnostics.fmt("input.zon")});
25992599 }
26002600 }
26012601
......@@ -2606,7 +2606,7 @@ test "std.zon string literal" {
26062606 .gpa = gpa,
26072607 .arena = arena,
26082608 .source = "\"abc\"",
2609 .errors = &errors,
2609 .diagnostics = &diagnostics,
26102610 });
26112611 try std.testing.expectEqualStrings("abc", parsed);
26122612 try std.testing.expectEqual(@as(u8, 0), parsed[3]);
......@@ -2617,7 +2617,7 @@ test "std.zon string literal" {
26172617 .gpa = gpa,
26182618 .arena = arena,
26192619 .source = "\\\\abc",
2620 .errors = &errors,
2620 .diagnostics = &diagnostics,
26212621 });
26222622 try std.testing.expectEqualStrings("abc", parsed);
26232623 try std.testing.expectEqual(@as(u8, 0), parsed[3]);
......@@ -2629,23 +2629,23 @@ test "std.zon string literal" {
26292629 {
26302630 try std.testing.expectError(
26312631 error.ParseZon,
2632 fromSlice([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\"foo\"", .errors = &errors }),
2632 fromSlice([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\"foo\"", .diagnostics = &diagnostics }),
26332633 );
26342634 try std.testing.expectFmt(
26352635 \\input.zon:1:1: error: expected array
26362636 \\
2637 , "{f}", .{errors.fmt("input.zon")});
2637 , "{f}", .{diagnostics.fmt("input.zon")});
26382638 }
26392639
26402640 {
26412641 try std.testing.expectError(
26422642 error.ParseZon,
2643 fromSlice([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\foo", .errors = &errors }),
2643 fromSlice([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\foo", .diagnostics = &diagnostics }),
26442644 );
26452645 try std.testing.expectFmt(
26462646 \\input.zon:1:1: error: expected array
26472647 \\
2648 , "{f}", .{errors.fmt("input.zon")});
2648 , "{f}", .{diagnostics.fmt("input.zon")});
26492649 }
26502650 }
26512651
......@@ -2653,36 +2653,36 @@ test "std.zon string literal" {
26532653 {
26542654 try std.testing.expectError(
26552655 error.ParseZon,
2656 fromSlice([]const u8, .{ .gpa = gpa, .arena = arena, .source = "true", .errors = &errors }),
2656 fromSlice([]const u8, .{ .gpa = gpa, .arena = arena, .source = "true", .diagnostics = &diagnostics }),
26572657 );
26582658 try std.testing.expectFmt(
26592659 \\input.zon:1:1: error: expected string
26602660 \\
2661 , "{f}", .{errors.fmt("input.zon")});
2661 , "{f}", .{diagnostics.fmt("input.zon")});
26622662 }
26632663
26642664 // Expecting string literal, getting an incompatible tuple
26652665 {
26662666 try std.testing.expectError(
26672667 error.ParseZon,
2668 fromSlice([]const u8, .{ .gpa = gpa, .arena = arena, .source = ".{false}", .errors = &errors }),
2668 fromSlice([]const u8, .{ .gpa = gpa, .arena = arena, .source = ".{false}", .diagnostics = &diagnostics }),
26692669 );
26702670 try std.testing.expectFmt(
26712671 \\input.zon:1:3: error: expected type 'u8'
26722672 \\
2673 , "{f}", .{errors.fmt("input.zon")});
2673 , "{f}", .{diagnostics.fmt("input.zon")});
26742674 }
26752675
26762676 // Invalid string literal
26772677 {
26782678 try std.testing.expectError(
26792679 error.ParseZon,
2680 fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"\\a\"", .errors = &errors }),
2680 fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"\\a\"", .diagnostics = &diagnostics }),
26812681 );
26822682 try std.testing.expectFmt(
26832683 \\input.zon:1:3: error: invalid escape character: 'a'
26842684 \\
2685 , "{f}", .{errors.fmt("input.zon")});
2685 , "{f}", .{diagnostics.fmt("input.zon")});
26862686 }
26872687
26882688 // Slice wrong child type
......@@ -2690,23 +2690,23 @@ test "std.zon string literal" {
26902690 {
26912691 try std.testing.expectError(
26922692 error.ParseZon,
2693 fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"a\"", .errors = &errors }),
2693 fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"a\"", .diagnostics = &diagnostics }),
26942694 );
26952695 try std.testing.expectFmt(
26962696 \\input.zon:1:1: error: expected array
26972697 \\
2698 , "{f}", .{errors.fmt("input.zon")});
2698 , "{f}", .{diagnostics.fmt("input.zon")});
26992699 }
27002700
27012701 {
27022702 try std.testing.expectError(
27032703 error.ParseZon,
2704 fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\\\\a", .errors = &errors }),
2704 fromSlice([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\\\\a", .diagnostics = &diagnostics }),
27052705 );
27062706 try std.testing.expectFmt(
27072707 \\input.zon:1:1: error: expected array
27082708 \\
2709 , "{f}", .{errors.fmt("input.zon")});
2709 , "{f}", .{diagnostics.fmt("input.zon")});
27102710 }
27112711 }
27122712
......@@ -2719,13 +2719,13 @@ test "std.zon string literal" {
27192719 .gpa = gpa,
27202720 .arena = arena,
27212721 .source = "\"abc\"",
2722 .errors = &errors,
2722 .diagnostics = &diagnostics,
27232723 }),
27242724 );
27252725 try std.testing.expectFmt(
27262726 \\input.zon:1:1: error: expected array
27272727 \\
2728 , "{f}", .{errors.fmt("input.zon")});
2728 , "{f}", .{diagnostics.fmt("input.zon")});
27292729 }
27302730
27312731 {
......@@ -2735,13 +2735,13 @@ test "std.zon string literal" {
27352735 .gpa = gpa,
27362736 .arena = arena,
27372737 .source = "\\\\abc",
2738 .errors = &errors,
2738 .diagnostics = &diagnostics,
27392739 }),
27402740 );
27412741 try std.testing.expectFmt(
27422742 \\input.zon:1:1: error: expected array
27432743 \\
2744 , "{f}", .{errors.fmt("input.zon")});
2744 , "{f}", .{diagnostics.fmt("input.zon")});
27452745 }
27462746 }
27472747
......@@ -2775,7 +2775,7 @@ test "std.zon string literal" {
27752775 \\ \\and this.
27762776 \\}
27772777 ,
2778 .errors = &errors,
2778 .diagnostics = &diagnostics,
27792779 });
27802780 try std.testing.expectEqualStrings(
27812781 "hello, world!\nthis is a multiline string!\n\n...",
......@@ -2792,7 +2792,7 @@ test "std.zon enum literals" {
27922792 var arena_allocator: ArenaAllocator = .init(gpa);
27932793 defer arena_allocator.deinit();
27942794 const arena = arena_allocator.allocator();
2795 var errors: Errors = .empty;
2795 var diagnostics: Diagnostics = .empty;
27962796
27972797 const Enum = enum {
27982798 foo,
......@@ -2806,19 +2806,19 @@ test "std.zon enum literals" {
28062806 .gpa = gpa,
28072807 .arena = arena,
28082808 .source = ".foo",
2809 .errors = &errors,
2809 .diagnostics = &diagnostics,
28102810 }));
28112811 try std.testing.expectEqual(Enum.bar, try fromSliceNoAlloc(Enum, .{
28122812 .gpa = gpa,
28132813 .arena = arena,
28142814 .source = ".bar",
2815 .errors = &errors,
2815 .diagnostics = &diagnostics,
28162816 }));
28172817 try std.testing.expectEqual(Enum.baz, try fromSliceNoAlloc(Enum, .{
28182818 .gpa = gpa,
28192819 .arena = arena,
28202820 .source = ".baz",
2821 .errors = &errors,
2821 .diagnostics = &diagnostics,
28222822 }));
28232823 try std.testing.expectEqual(
28242824 Enum.@"ab\nc",
......@@ -2826,7 +2826,7 @@ test "std.zon enum literals" {
28262826 .gpa = gpa,
28272827 .arena = arena,
28282828 .source = ".@\"ab\\nc\"",
2829 .errors = &errors,
2829 .diagnostics = &diagnostics,
28302830 }),
28312831 );
28322832
......@@ -2838,14 +2838,14 @@ test "std.zon enum literals" {
28382838 .gpa = gpa,
28392839 .arena = arena,
28402840 .source = ".qux",
2841 .errors = &errors,
2841 .diagnostics = &diagnostics,
28422842 }),
28432843 );
28442844 try std.testing.expectFmt(
28452845 \\input.zon:1:2: error: unexpected enum literal 'qux'
28462846 \\input.zon:1:2: note: supported: 'foo', 'bar', 'baz', '@"ab\nc"'
28472847 \\
2848 , "{f}", .{errors.fmt("input.zon")});
2848 , "{f}", .{diagnostics.fmt("input.zon")});
28492849 }
28502850
28512851 // Bad tag that's too long for parser
......@@ -2856,14 +2856,14 @@ test "std.zon enum literals" {
28562856 .gpa = gpa,
28572857 .arena = arena,
28582858 .source = ".@\"foobarbaz\"",
2859 .errors = &errors,
2859 .diagnostics = &diagnostics,
28602860 }),
28612861 );
28622862 try std.testing.expectFmt(
28632863 \\input.zon:1:2: error: unexpected enum literal 'foobarbaz'
28642864 \\input.zon:1:2: note: supported: 'foo', 'bar', 'baz', '@"ab\nc"'
28652865 \\
2866 , "{f}", .{errors.fmt("input.zon")});
2866 , "{f}", .{diagnostics.fmt("input.zon")});
28672867 }
28682868
28692869 // Bad type
......@@ -2874,13 +2874,13 @@ test "std.zon enum literals" {
28742874 .gpa = gpa,
28752875 .arena = arena,
28762876 .source = "true",
2877 .errors = &errors,
2877 .diagnostics = &diagnostics,
28782878 }),
28792879 );
28802880 try std.testing.expectFmt(
28812881 \\input.zon:1:1: error: expected enum literal
28822882 \\
2883 , "{f}", .{errors.fmt("input.zon")});
2883 , "{f}", .{diagnostics.fmt("input.zon")});
28842884 }
28852885
28862886 // Test embedded nulls in an identifier
......@@ -2891,13 +2891,13 @@ test "std.zon enum literals" {
28912891 .gpa = gpa,
28922892 .arena = arena,
28932893 .source = ".@\"\\x00\"",
2894 .errors = &errors,
2894 .diagnostics = &diagnostics,
28952895 }),
28962896 );
28972897 try std.testing.expectFmt(
28982898 \\input.zon:1:2: error: identifier cannot contain null bytes
28992899 \\
2900 , "{f}", .{errors.fmt("input.zon")});
2900 , "{f}", .{diagnostics.fmt("input.zon")});
29012901 }
29022902}
29032903
......@@ -2906,20 +2906,20 @@ test "std.zon parse bool" {
29062906 var arena_allocator: ArenaAllocator = .init(gpa);
29072907 defer arena_allocator.deinit();
29082908 const arena = arena_allocator.allocator();
2909 var errors: Errors = .empty;
2909 var diagnostics: Diagnostics = .empty;
29102910
29112911 // Correct bools
29122912 try std.testing.expectEqual(true, try fromSliceNoAlloc(bool, .{
29132913 .gpa = gpa,
29142914 .arena = arena,
29152915 .source = "true",
2916 .errors = &errors,
2916 .diagnostics = &diagnostics,
29172917 }));
29182918 try std.testing.expectEqual(false, try fromSliceNoAlloc(bool, .{
29192919 .gpa = gpa,
29202920 .arena = arena,
29212921 .source = "false",
2922 .errors = &errors,
2922 .diagnostics = &diagnostics,
29232923 }));
29242924
29252925 // Errors
......@@ -2930,7 +2930,7 @@ test "std.zon parse bool" {
29302930 .gpa = gpa,
29312931 .arena = arena,
29322932 .source = " foo",
2933 .errors = &errors,
2933 .diagnostics = &diagnostics,
29342934 }),
29352935 );
29362936 try std.testing.expectFmt(
......@@ -2938,19 +2938,19 @@ test "std.zon parse bool" {
29382938 \\input.zon:1:2: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
29392939 \\input.zon:1:2: note: precede identifier with '.' for an enum literal
29402940 \\
2941 , "{f}", .{errors.fmt("input.zon")});
2941 , "{f}", .{diagnostics.fmt("input.zon")});
29422942 }
29432943 {
29442944 try std.testing.expectError(error.ParseZon, fromSliceNoAlloc(bool, .{
29452945 .gpa = gpa,
29462946 .arena = arena,
29472947 .source = "123",
2948 .errors = &errors,
2948 .diagnostics = &diagnostics,
29492949 }));
29502950 try std.testing.expectFmt(
29512951 \\input.zon:1:1: error: expected type 'bool'
29522952 \\
2953 , "{f}", .{errors.fmt("input.zon")});
2953 , "{f}", .{diagnostics.fmt("input.zon")});
29542954 }
29552955}
29562956
......@@ -2981,32 +2981,32 @@ test "std.zon parse int" {
29812981 var arena_allocator: ArenaAllocator = .init(gpa);
29822982 defer arena_allocator.deinit();
29832983 const arena = arena_allocator.allocator();
2984 var errors: Errors = .empty;
2984 var diagnostics: Diagnostics = .empty;
29852985
29862986 // Test various numbers and types
29872987 try std.testing.expectEqual(@as(u8, 10), try fromSliceNoAlloc(u8, .{
29882988 .gpa = gpa,
29892989 .arena = arena,
29902990 .source = "10",
2991 .errors = &errors,
2991 .diagnostics = &diagnostics,
29922992 }));
29932993 try std.testing.expectEqual(@as(i16, 24), try fromSliceNoAlloc(i16, .{
29942994 .gpa = gpa,
29952995 .arena = arena,
29962996 .source = "24",
2997 .errors = &errors,
2997 .diagnostics = &diagnostics,
29982998 }));
29992999 try std.testing.expectEqual(@as(i14, -4), try fromSliceNoAlloc(i14, .{
30003000 .gpa = gpa,
30013001 .arena = arena,
30023002 .source = "-4",
3003 .errors = &errors,
3003 .diagnostics = &diagnostics,
30043004 }));
30053005 try std.testing.expectEqual(@as(i32, -123), try fromSliceNoAlloc(i32, .{
30063006 .gpa = gpa,
30073007 .arena = arena,
30083008 .source = "-123",
3009 .errors = &errors,
3009 .diagnostics = &diagnostics,
30103010 }));
30113011
30123012 // Test limits
......@@ -3014,13 +3014,13 @@ test "std.zon parse int" {
30143014 .gpa = gpa,
30153015 .arena = arena,
30163016 .source = "127",
3017 .errors = &errors,
3017 .diagnostics = &diagnostics,
30183018 }));
30193019 try std.testing.expectEqual(@as(i8, -128), try fromSliceNoAlloc(i8, .{
30203020 .gpa = gpa,
30213021 .arena = arena,
30223022 .source = "-128",
3023 .errors = &errors,
3023 .diagnostics = &diagnostics,
30243024 }));
30253025
30263026 // Test characters
......@@ -3028,13 +3028,13 @@ test "std.zon parse int" {
30283028 .gpa = gpa,
30293029 .arena = arena,
30303030 .source = "'a'",
3031 .errors = &errors,
3031 .diagnostics = &diagnostics,
30323032 }));
30333033 try std.testing.expectEqual(@as(u8, 'z'), try fromSliceNoAlloc(u8, .{
30343034 .gpa = gpa,
30353035 .arena = arena,
30363036 .source = "'z'",
3037 .errors = &errors,
3037 .diagnostics = &diagnostics,
30383038 }));
30393039
30403040 // Test big integers
......@@ -3044,7 +3044,7 @@ test "std.zon parse int" {
30443044 .gpa = gpa,
30453045 .arena = arena,
30463046 .source = "36893488147419103231",
3047 .errors = &errors,
3047 .diagnostics = &diagnostics,
30483048 }),
30493049 );
30503050 try std.testing.expectEqual(
......@@ -3053,7 +3053,7 @@ test "std.zon parse int" {
30533053 .gpa = gpa,
30543054 .arena = arena,
30553055 .source = "368934_881_474191032_31",
3056 .errors = &errors,
3056 .diagnostics = &diagnostics,
30573057 }),
30583058 );
30593059 try std.testing.expectEqual(
......@@ -3062,7 +3062,7 @@ test "std.zon parse int" {
30623062 .gpa = gpa,
30633063 .arena = arena,
30643064 .source = "340282366920938463463374607431768211455",
3065 .errors = &errors,
3065 .diagnostics = &diagnostics,
30663066 }),
30673067 );
30683068
......@@ -3073,7 +3073,7 @@ test "std.zon parse int" {
30733073 .gpa = gpa,
30743074 .arena = arena,
30753075 .source = "36893488147419103231",
3076 .errors = &errors,
3076 .diagnostics = &diagnostics,
30773077 }),
30783078 );
30793079 try std.testing.expectEqual(
......@@ -3082,7 +3082,7 @@ test "std.zon parse int" {
30823082 .gpa = gpa,
30833083 .arena = arena,
30843084 .source = "-36893488147419103232",
3085 .errors = &errors,
3085 .diagnostics = &diagnostics,
30863086 }),
30873087 );
30883088 {
......@@ -3090,24 +3090,24 @@ test "std.zon parse int" {
30903090 .gpa = gpa,
30913091 .arena = arena,
30923092 .source = "36893488147419103232",
3093 .errors = &errors,
3093 .diagnostics = &diagnostics,
30943094 }));
30953095 try std.testing.expectFmt(
30963096 \\input.zon:1:1: error: type 'i66' cannot represent value
30973097 \\
3098 , "{f}", .{errors.fmt("input.zon")});
3098 , "{f}", .{diagnostics.fmt("input.zon")});
30993099 }
31003100 {
31013101 try std.testing.expectError(error.ParseZon, fromSliceNoAlloc(i66, .{
31023102 .gpa = gpa,
31033103 .arena = arena,
31043104 .source = "-36893488147419103233",
3105 .errors = &errors,
3105 .diagnostics = &diagnostics,
31063106 }));
31073107 try std.testing.expectFmt(
31083108 \\input.zon:1:1: error: type 'i66' cannot represent value
31093109 \\
3110 , "{f}", .{errors.fmt("input.zon")});
3110 , "{f}", .{diagnostics.fmt("input.zon")});
31113111 }
31123112
31133113 // Test parsing whole number floats as integers
......@@ -3115,13 +3115,13 @@ test "std.zon parse int" {
31153115 .gpa = gpa,
31163116 .arena = arena,
31173117 .source = "-1.0",
3118 .errors = &errors,
3118 .diagnostics = &diagnostics,
31193119 }));
31203120 try std.testing.expectEqual(@as(i8, 123), try fromSliceNoAlloc(i8, .{
31213121 .gpa = gpa,
31223122 .arena = arena,
31233123 .source = "123.0",
3124 .errors = &errors,
3124 .diagnostics = &diagnostics,
31253125 }));
31263126
31273127 // Test non-decimal integers
......@@ -3129,37 +3129,37 @@ test "std.zon parse int" {
31293129 .gpa = gpa,
31303130 .arena = arena,
31313131 .source = "0xff",
3132 .errors = &errors,
3132 .diagnostics = &diagnostics,
31333133 }));
31343134 try std.testing.expectEqual(@as(i16, -0xff), try fromSliceNoAlloc(i16, .{
31353135 .gpa = gpa,
31363136 .arena = arena,
31373137 .source = "-0xff",
3138 .errors = &errors,
3138 .diagnostics = &diagnostics,
31393139 }));
31403140 try std.testing.expectEqual(@as(i16, 0o77), try fromSliceNoAlloc(i16, .{
31413141 .gpa = gpa,
31423142 .arena = arena,
31433143 .source = "0o77",
3144 .errors = &errors,
3144 .diagnostics = &diagnostics,
31453145 }));
31463146 try std.testing.expectEqual(@as(i16, -0o77), try fromSliceNoAlloc(i16, .{
31473147 .gpa = gpa,
31483148 .arena = arena,
31493149 .source = "-0o77",
3150 .errors = &errors,
3150 .diagnostics = &diagnostics,
31513151 }));
31523152 try std.testing.expectEqual(@as(i16, 0b11), try fromSliceNoAlloc(i16, .{
31533153 .gpa = gpa,
31543154 .arena = arena,
31553155 .source = "0b11",
3156 .errors = &errors,
3156 .diagnostics = &diagnostics,
31573157 }));
31583158 try std.testing.expectEqual(@as(i16, -0b11), try fromSliceNoAlloc(i16, .{
31593159 .gpa = gpa,
31603160 .arena = arena,
31613161 .source = "-0b11",
3162 .errors = &errors,
3162 .diagnostics = &diagnostics,
31633163 }));
31643164
31653165 // Test non-decimal big integers
......@@ -3167,55 +3167,55 @@ test "std.zon parse int" {
31673167 .gpa = gpa,
31683168 .arena = arena,
31693169 .source = "0x1ffffffffffffffff",
3170 .errors = &errors,
3170 .diagnostics = &diagnostics,
31713171 }));
31723172 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{
31733173 .gpa = gpa,
31743174 .arena = arena,
31753175 .source = "0x1ffffffffffffffff",
3176 .errors = &errors,
3176 .diagnostics = &diagnostics,
31773177 }));
31783178 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{
31793179 .gpa = gpa,
31803180 .arena = arena,
31813181 .source = "-0x1ffffffffffffffff",
3182 .errors = &errors,
3182 .diagnostics = &diagnostics,
31833183 }));
31843184 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSliceNoAlloc(u65, .{
31853185 .gpa = gpa,
31863186 .arena = arena,
31873187 .source = "0o3777777777777777777777",
3188 .errors = &errors,
3188 .diagnostics = &diagnostics,
31893189 }));
31903190 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{
31913191 .gpa = gpa,
31923192 .arena = arena,
31933193 .source = "0o3777777777777777777777",
3194 .errors = &errors,
3194 .diagnostics = &diagnostics,
31953195 }));
31963196 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{
31973197 .gpa = gpa,
31983198 .arena = arena,
31993199 .source = "-0o3777777777777777777777",
3200 .errors = &errors,
3200 .diagnostics = &diagnostics,
32013201 }));
32023202 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSliceNoAlloc(u65, .{
32033203 .gpa = gpa,
32043204 .arena = arena,
32053205 .source = "0b11111111111111111111111111111111111111111111111111111111111111111",
3206 .errors = &errors,
3206 .diagnostics = &diagnostics,
32073207 }));
32083208 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{
32093209 .gpa = gpa,
32103210 .arena = arena,
32113211 .source = "0b11111111111111111111111111111111111111111111111111111111111111111",
3212 .errors = &errors,
3212 .diagnostics = &diagnostics,
32133213 }));
32143214 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSliceNoAlloc(i66, .{
32153215 .gpa = gpa,
32163216 .arena = arena,
32173217 .source = "-0b11111111111111111111111111111111111111111111111111111111111111111",
3218 .errors = &errors,
3218 .diagnostics = &diagnostics,
32193219 }));
32203220
32213221 // Number with invalid character in the middle
......@@ -3224,12 +3224,12 @@ test "std.zon parse int" {
32243224 .gpa = gpa,
32253225 .arena = arena,
32263226 .source = "32a32",
3227 .errors = &errors,
3227 .diagnostics = &diagnostics,
32283228 }));
32293229 try std.testing.expectFmt(
32303230 \\input.zon:1:3: error: invalid digit 'a' for decimal base
32313231 \\
3232 , "{f}", .{errors.fmt("input.zon")});
3232 , "{f}", .{diagnostics.fmt("input.zon")});
32333233 }
32343234
32353235 // Failing to parse as int
......@@ -3238,12 +3238,12 @@ test "std.zon parse int" {
32383238 .gpa = gpa,
32393239 .arena = arena,
32403240 .source = "true",
3241 .errors = &errors,
3241 .diagnostics = &diagnostics,
32423242 }));
32433243 try std.testing.expectFmt(
32443244 \\input.zon:1:1: error: expected type 'u8'
32453245 \\
3246 , "{f}", .{errors.fmt("input.zon")});
3246 , "{f}", .{diagnostics.fmt("input.zon")});
32473247 }
32483248
32493249 // Failing because an int is out of range
......@@ -3252,12 +3252,12 @@ test "std.zon parse int" {
32523252 .gpa = gpa,
32533253 .arena = arena,
32543254 .source = "256",
3255 .errors = &errors,
3255 .diagnostics = &diagnostics,
32563256 }));
32573257 try std.testing.expectFmt(
32583258 \\input.zon:1:1: error: type 'u8' cannot represent value
32593259 \\
3260 , "{f}", .{errors.fmt("input.zon")});
3260 , "{f}", .{diagnostics.fmt("input.zon")});
32613261 }
32623262
32633263 // Failing because a negative int is out of range
......@@ -3266,12 +3266,12 @@ test "std.zon parse int" {
32663266 .gpa = gpa,
32673267 .arena = arena,
32683268 .source = "-129",
3269 .errors = &errors,
3269 .diagnostics = &diagnostics,
32703270 }));
32713271 try std.testing.expectFmt(
32723272 \\input.zon:1:1: error: type 'i8' cannot represent value
32733273 \\
3274 , "{f}", .{errors.fmt("input.zon")});
3274 , "{f}", .{diagnostics.fmt("input.zon")});
32753275 }
32763276
32773277 // Failing because an unsigned int is negative
......@@ -3280,12 +3280,12 @@ test "std.zon parse int" {
32803280 .gpa = gpa,
32813281 .arena = arena,
32823282 .source = "-1",
3283 .errors = &errors,
3283 .diagnostics = &diagnostics,
32843284 }));
32853285 try std.testing.expectFmt(
32863286 \\input.zon:1:1: error: type 'u8' cannot represent value
32873287 \\
3288 , "{f}", .{errors.fmt("input.zon")});
3288 , "{f}", .{diagnostics.fmt("input.zon")});
32893289 }
32903290
32913291 // Failing because a float is non-whole
......@@ -3294,12 +3294,12 @@ test "std.zon parse int" {
32943294 .gpa = gpa,
32953295 .arena = arena,
32963296 .source = "1.5",
3297 .errors = &errors,
3297 .diagnostics = &diagnostics,
32983298 }));
32993299 try std.testing.expectFmt(
33003300 \\input.zon:1:1: error: type 'u8' cannot represent value
33013301 \\
3302 , "{f}", .{errors.fmt("input.zon")});
3302 , "{f}", .{diagnostics.fmt("input.zon")});
33033303 }
33043304
33053305 // Failing because a float is negative
......@@ -3308,12 +3308,12 @@ test "std.zon parse int" {
33083308 .gpa = gpa,
33093309 .arena = arena,
33103310 .source = "-1.0",
3311 .errors = &errors,
3311 .diagnostics = &diagnostics,
33123312 }));
33133313 try std.testing.expectFmt(
33143314 \\input.zon:1:1: error: type 'u8' cannot represent value
33153315 \\
3316 , "{f}", .{errors.fmt("input.zon")});
3316 , "{f}", .{diagnostics.fmt("input.zon")});
33173317 }
33183318
33193319 // Negative integer zero
......@@ -3322,14 +3322,14 @@ test "std.zon parse int" {
33223322 .gpa = gpa,
33233323 .arena = arena,
33243324 .source = "-0",
3325 .errors = &errors,
3325 .diagnostics = &diagnostics,
33263326 }));
33273327 try std.testing.expectFmt(
33283328 \\input.zon:1:2: error: integer literal '-0' is ambiguous
33293329 \\input.zon:1:2: note: use '0' for an integer zero
33303330 \\input.zon:1:2: note: use '-0.0' for a floating-point signed zero
33313331 \\
3332 , "{f}", .{errors.fmt("input.zon")});
3332 , "{f}", .{diagnostics.fmt("input.zon")});
33333333 }
33343334
33353335 // Negative integer zero casted to float
......@@ -3338,14 +3338,14 @@ test "std.zon parse int" {
33383338 .gpa = gpa,
33393339 .arena = arena,
33403340 .source = "-0",
3341 .errors = &errors,
3341 .diagnostics = &diagnostics,
33423342 }));
33433343 try std.testing.expectFmt(
33443344 \\input.zon:1:2: error: integer literal '-0' is ambiguous
33453345 \\input.zon:1:2: note: use '0' for an integer zero
33463346 \\input.zon:1:2: note: use '-0.0' for a floating-point signed zero
33473347 \\
3348 , "{f}", .{errors.fmt("input.zon")});
3348 , "{f}", .{diagnostics.fmt("input.zon")});
33493349 }
33503350
33513351 // Negative float 0 is allowed
......@@ -3354,14 +3354,14 @@ test "std.zon parse int" {
33543354 .gpa = gpa,
33553355 .arena = arena,
33563356 .source = "-0.0",
3357 .errors = &errors,
3357 .diagnostics = &diagnostics,
33583358 })),
33593359 );
33603360 try std.testing.expect(std.math.isPositiveZero(try fromSliceNoAlloc(f32, .{
33613361 .gpa = gpa,
33623362 .arena = arena,
33633363 .source = "0.0",
3364 .errors = &errors,
3364 .diagnostics = &diagnostics,
33653365 })));
33663366
33673367 // Double negation is not allowed
......@@ -3370,12 +3370,12 @@ test "std.zon parse int" {
33703370 .gpa = gpa,
33713371 .arena = arena,
33723372 .source = "--2",
3373 .errors = &errors,
3373 .diagnostics = &diagnostics,
33743374 }));
33753375 try std.testing.expectFmt(
33763376 \\input.zon:1:1: error: expected number or 'inf' after '-'
33773377 \\
3378 , "{f}", .{errors.fmt("input.zon")});
3378 , "{f}", .{diagnostics.fmt("input.zon")});
33793379 }
33803380
33813381 {
......@@ -3385,13 +3385,13 @@ test "std.zon parse int" {
33853385 .gpa = gpa,
33863386 .arena = arena,
33873387 .source = "--2.0",
3388 .errors = &errors,
3388 .diagnostics = &diagnostics,
33893389 }),
33903390 );
33913391 try std.testing.expectFmt(
33923392 \\input.zon:1:1: error: expected number or 'inf' after '-'
33933393 \\
3394 , "{f}", .{errors.fmt("input.zon")});
3394 , "{f}", .{diagnostics.fmt("input.zon")});
33953395 }
33963396
33973397 // Invalid int literal
......@@ -3400,12 +3400,12 @@ test "std.zon parse int" {
34003400 .gpa = gpa,
34013401 .arena = arena,
34023402 .source = "0xg",
3403 .errors = &errors,
3403 .diagnostics = &diagnostics,
34043404 }));
34053405 try std.testing.expectFmt(
34063406 \\input.zon:1:3: error: invalid digit 'g' for hex base
34073407 \\
3408 , "{f}", .{errors.fmt("input.zon")});
3408 , "{f}", .{diagnostics.fmt("input.zon")});
34093409 }
34103410
34113411 // Notes on invalid int literal
......@@ -3414,13 +3414,13 @@ test "std.zon parse int" {
34143414 .gpa = gpa,
34153415 .arena = arena,
34163416 .source = "0123",
3417 .errors = &errors,
3417 .diagnostics = &diagnostics,
34183418 }));
34193419 try std.testing.expectFmt(
34203420 \\input.zon:1:1: error: number '0123' has leading zero
34213421 \\input.zon:1:1: note: use '0o' prefix for octal literals
34223422 \\
3423 , "{f}", .{errors.fmt("input.zon")});
3423 , "{f}", .{diagnostics.fmt("input.zon")});
34243424 }
34253425}
34263426
......@@ -3429,31 +3429,31 @@ test "std.zon negative char" {
34293429 var arena_allocator: ArenaAllocator = .init(gpa);
34303430 defer arena_allocator.deinit();
34313431 const arena = arena_allocator.allocator();
3432 var errors: Errors = .empty;
3432 var diagnostics: Diagnostics = .empty;
34333433
34343434 {
34353435 try std.testing.expectError(error.ParseZon, fromSliceNoAlloc(f32, .{
34363436 .gpa = gpa,
34373437 .arena = arena,
34383438 .source = "-'a'",
3439 .errors = &errors,
3439 .diagnostics = &diagnostics,
34403440 }));
34413441 try std.testing.expectFmt(
34423442 \\input.zon:1:1: error: expected number or 'inf' after '-'
34433443 \\
3444 , "{f}", .{errors.fmt("input.zon")});
3444 , "{f}", .{diagnostics.fmt("input.zon")});
34453445 }
34463446 {
34473447 try std.testing.expectError(error.ParseZon, fromSliceNoAlloc(i16, .{
34483448 .gpa = gpa,
34493449 .arena = arena,
34503450 .source = "-'a'",
3451 .errors = &errors,
3451 .diagnostics = &diagnostics,
34523452 }));
34533453 try std.testing.expectFmt(
34543454 \\input.zon:1:1: error: expected number or 'inf' after '-'
34553455 \\
3456 , "{f}", .{errors.fmt("input.zon")});
3456 , "{f}", .{diagnostics.fmt("input.zon")});
34573457 }
34583458}
34593459
......@@ -3464,14 +3464,14 @@ test "std.zon parse float" {
34643464 var arena_allocator: ArenaAllocator = .init(gpa);
34653465 defer arena_allocator.deinit();
34663466 const arena = arena_allocator.allocator();
3467 var errors: Errors = .empty;
3467 var diagnostics: Diagnostics = .empty;
34683468
34693469 // Test decimals
34703470 try std.testing.expectEqual(@as(f16, 0.5), try fromSliceNoAlloc(f16, .{
34713471 .gpa = gpa,
34723472 .arena = arena,
34733473 .source = "0.5",
3474 .errors = &errors,
3474 .diagnostics = &diagnostics,
34753475 }));
34763476 try std.testing.expectEqual(
34773477 @as(f32, 123.456),
......@@ -3479,7 +3479,7 @@ test "std.zon parse float" {
34793479 .gpa = gpa,
34803480 .arena = arena,
34813481 .source = "123.456",
3482 .errors = &errors,
3482 .diagnostics = &diagnostics,
34833483 }),
34843484 );
34853485 try std.testing.expectEqual(
......@@ -3488,14 +3488,14 @@ test "std.zon parse float" {
34883488 .gpa = gpa,
34893489 .arena = arena,
34903490 .source = "-123.456",
3491 .errors = &errors,
3491 .diagnostics = &diagnostics,
34923492 }),
34933493 );
34943494 try std.testing.expectEqual(@as(f128, 42.5), try fromSliceNoAlloc(f128, .{
34953495 .gpa = gpa,
34963496 .arena = arena,
34973497 .source = "42.5",
3498 .errors = &errors,
3498 .diagnostics = &diagnostics,
34993499 }));
35003500
35013501 // Test whole numbers with and without decimals
......@@ -3503,25 +3503,25 @@ test "std.zon parse float" {
35033503 .gpa = gpa,
35043504 .arena = arena,
35053505 .source = "5.0",
3506 .errors = &errors,
3506 .diagnostics = &diagnostics,
35073507 }));
35083508 try std.testing.expectEqual(@as(f16, 5.0), try fromSliceNoAlloc(f16, .{
35093509 .gpa = gpa,
35103510 .arena = arena,
35113511 .source = "5",
3512 .errors = &errors,
3512 .diagnostics = &diagnostics,
35133513 }));
35143514 try std.testing.expectEqual(@as(f32, -102), try fromSliceNoAlloc(f32, .{
35153515 .gpa = gpa,
35163516 .arena = arena,
35173517 .source = "-102.0",
3518 .errors = &errors,
3518 .diagnostics = &diagnostics,
35193519 }));
35203520 try std.testing.expectEqual(@as(f32, -102), try fromSliceNoAlloc(f32, .{
35213521 .gpa = gpa,
35223522 .arena = arena,
35233523 .source = "-102",
3524 .errors = &errors,
3524 .diagnostics = &diagnostics,
35253525 }));
35263526
35273527 // Test characters and negated characters
......@@ -3529,13 +3529,13 @@ test "std.zon parse float" {
35293529 .gpa = gpa,
35303530 .arena = arena,
35313531 .source = "'a'",
3532 .errors = &errors,
3532 .diagnostics = &diagnostics,
35333533 }));
35343534 try std.testing.expectEqual(@as(f32, 'z'), try fromSliceNoAlloc(f32, .{
35353535 .gpa = gpa,
35363536 .arena = arena,
35373537 .source = "'z'",
3538 .errors = &errors,
3538 .diagnostics = &diagnostics,
35393539 }));
35403540
35413541 // Test big integers
......@@ -3545,7 +3545,7 @@ test "std.zon parse float" {
35453545 .gpa = gpa,
35463546 .arena = arena,
35473547 .source = "36893488147419103231",
3548 .errors = &errors,
3548 .diagnostics = &diagnostics,
35493549 }),
35503550 );
35513551 try std.testing.expectEqual(
......@@ -3554,20 +3554,20 @@ test "std.zon parse float" {
35543554 .gpa = gpa,
35553555 .arena = arena,
35563556 .source = "-36893488147419103231",
3557 .errors = &errors,
3557 .diagnostics = &diagnostics,
35583558 }),
35593559 );
35603560 try std.testing.expectEqual(@as(f128, 0x1ffffffffffffffff), try fromSliceNoAlloc(f128, .{
35613561 .gpa = gpa,
35623562 .arena = arena,
35633563 .source = "0x1ffffffffffffffff",
3564 .errors = &errors,
3564 .diagnostics = &diagnostics,
35653565 }));
35663566 try std.testing.expectEqual(@as(f32, @floatFromInt(0x1ffffffffffffffff)), try fromSliceNoAlloc(f32, .{
35673567 .gpa = gpa,
35683568 .arena = arena,
35693569 .source = "0x1ffffffffffffffff",
3570 .errors = &errors,
3570 .diagnostics = &diagnostics,
35713571 }));
35723572
35733573 // Exponents, underscores
......@@ -3577,7 +3577,7 @@ test "std.zon parse float" {
35773577 .gpa = gpa,
35783578 .arena = arena,
35793579 .source = "12_3.0E+77",
3580 .errors = &errors,
3580 .diagnostics = &diagnostics,
35813581 }),
35823582 );
35833583
......@@ -3588,7 +3588,7 @@ test "std.zon parse float" {
35883588 .gpa = gpa,
35893589 .arena = arena,
35903590 .source = "0x103.70p-5",
3591 .errors = &errors,
3591 .diagnostics = &diagnostics,
35923592 }),
35933593 );
35943594 try std.testing.expectEqual(
......@@ -3597,7 +3597,7 @@ test "std.zon parse float" {
35973597 .gpa = gpa,
35983598 .arena = arena,
35993599 .source = "-0x103.70",
3600 .errors = &errors,
3600 .diagnostics = &diagnostics,
36013601 }),
36023602 );
36033603 try std.testing.expectEqual(
......@@ -3606,7 +3606,7 @@ test "std.zon parse float" {
36063606 .gpa = gpa,
36073607 .arena = arena,
36083608 .source = "0x1234_5678.9ABC_CDEFp-10",
3609 .errors = &errors,
3609 .diagnostics = &diagnostics,
36103610 }),
36113611 );
36123612
......@@ -3615,19 +3615,19 @@ test "std.zon parse float" {
36153615 .gpa = gpa,
36163616 .arena = arena,
36173617 .source = "inf",
3618 .errors = &errors,
3618 .diagnostics = &diagnostics,
36193619 })));
36203620 try std.testing.expect(std.math.isNegativeInf(try fromSliceNoAlloc(f32, .{
36213621 .gpa = gpa,
36223622 .arena = arena,
36233623 .source = "-inf",
3624 .errors = &errors,
3624 .diagnostics = &diagnostics,
36253625 })));
36263626 try std.testing.expect(std.math.isNan(try fromSliceNoAlloc(f32, .{
36273627 .gpa = gpa,
36283628 .arena = arena,
36293629 .source = "nan",
3630 .errors = &errors,
3630 .diagnostics = &diagnostics,
36313631 })));
36323632
36333633 // Negative nan not allowed
......@@ -3636,12 +3636,12 @@ test "std.zon parse float" {
36363636 .gpa = gpa,
36373637 .arena = arena,
36383638 .source = "-nan",
3639 .errors = &errors,
3639 .diagnostics = &diagnostics,
36403640 }));
36413641 try std.testing.expectFmt(
36423642 \\input.zon:1:1: error: expected number or 'inf' after '-'
36433643 \\
3644 , "{f}", .{errors.fmt("input.zon")});
3644 , "{f}", .{diagnostics.fmt("input.zon")});
36453645 }
36463646
36473647 // nan as int not allowed
......@@ -3650,12 +3650,12 @@ test "std.zon parse float" {
36503650 .gpa = gpa,
36513651 .arena = arena,
36523652 .source = "nan",
3653 .errors = &errors,
3653 .diagnostics = &diagnostics,
36543654 }));
36553655 try std.testing.expectFmt(
36563656 \\input.zon:1:1: error: expected type 'i8'
36573657 \\
3658 , "{f}", .{errors.fmt("input.zon")});
3658 , "{f}", .{diagnostics.fmt("input.zon")});
36593659 }
36603660
36613661 // nan as int not allowed
......@@ -3664,12 +3664,12 @@ test "std.zon parse float" {
36643664 .gpa = gpa,
36653665 .arena = arena,
36663666 .source = "nan",
3667 .errors = &errors,
3667 .diagnostics = &diagnostics,
36683668 }));
36693669 try std.testing.expectFmt(
36703670 \\input.zon:1:1: error: expected type 'i8'
36713671 \\
3672 , "{f}", .{errors.fmt("input.zon")});
3672 , "{f}", .{diagnostics.fmt("input.zon")});
36733673 }
36743674
36753675 // inf as int not allowed
......@@ -3678,12 +3678,12 @@ test "std.zon parse float" {
36783678 .gpa = gpa,
36793679 .arena = arena,
36803680 .source = "inf",
3681 .errors = &errors,
3681 .diagnostics = &diagnostics,
36823682 }));
36833683 try std.testing.expectFmt(
36843684 \\input.zon:1:1: error: expected type 'i8'
36853685 \\
3686 , "{f}", .{errors.fmt("input.zon")});
3686 , "{f}", .{diagnostics.fmt("input.zon")});
36873687 }
36883688
36893689 // -inf as int not allowed
......@@ -3692,12 +3692,12 @@ test "std.zon parse float" {
36923692 .gpa = gpa,
36933693 .arena = arena,
36943694 .source = "-inf",
3695 .errors = &errors,
3695 .diagnostics = &diagnostics,
36963696 }));
36973697 try std.testing.expectFmt(
36983698 \\input.zon:1:1: error: expected type 'i8'
36993699 \\
3700 , "{f}", .{errors.fmt("input.zon")});
3700 , "{f}", .{diagnostics.fmt("input.zon")});
37013701 }
37023702
37033703 // Bad identifier as float
......@@ -3706,14 +3706,14 @@ test "std.zon parse float" {
37063706 .gpa = gpa,
37073707 .arena = arena,
37083708 .source = "foo",
3709 .errors = &errors,
3709 .diagnostics = &diagnostics,
37103710 }));
37113711 try std.testing.expectFmt(
37123712 \\input.zon:1:1: error: invalid expression
37133713 \\input.zon:1:1: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
37143714 \\input.zon:1:1: note: precede identifier with '.' for an enum literal
37153715 \\
3716 , "{f}", .{errors.fmt("input.zon")});
3716 , "{f}", .{diagnostics.fmt("input.zon")});
37173717 }
37183718
37193719 {
......@@ -3721,12 +3721,12 @@ test "std.zon parse float" {
37213721 .gpa = gpa,
37223722 .arena = arena,
37233723 .source = "-foo",
3724 .errors = &errors,
3724 .diagnostics = &diagnostics,
37253725 }));
37263726 try std.testing.expectFmt(
37273727 \\input.zon:1:1: error: expected number or 'inf' after '-'
37283728 \\
3729 , "{f}", .{errors.fmt("input.zon")});
3729 , "{f}", .{diagnostics.fmt("input.zon")});
37303730 }
37313731
37323732 // Non float as float
......@@ -3737,13 +3737,13 @@ test "std.zon parse float" {
37373737 .gpa = gpa,
37383738 .arena = arena,
37393739 .source = "\"foo\"",
3740 .errors = &errors,
3740 .diagnostics = &diagnostics,
37413741 }),
37423742 );
37433743 try std.testing.expectFmt(
37443744 \\input.zon:1:1: error: expected type 'f32'
37453745 \\
3746 , "{f}", .{errors.fmt("input.zon")});
3746 , "{f}", .{diagnostics.fmt("input.zon")});
37473747 }
37483748}
37493749
......@@ -3752,7 +3752,7 @@ test "std.zon free on error" {
37523752 var arena_allocator: ArenaAllocator = .init(gpa);
37533753 defer arena_allocator.deinit();
37543754 const arena = arena_allocator.allocator();
3755 var errors: Errors = .empty;
3755 var diagnostics: Diagnostics = .empty;
37563756
37573757 // Test freeing partially allocated structs
37583758 {
......@@ -3771,7 +3771,7 @@ test "std.zon free on error" {
37713771 \\ .z = "fail",
37723772 \\}
37733773 ,
3774 .errors = &errors,
3774 .diagnostics = &diagnostics,
37753775 }));
37763776 }
37773777
......@@ -3792,7 +3792,7 @@ test "std.zon free on error" {
37923792 \\ "fail",
37933793 \\}
37943794 ,
3795 .errors = &errors,
3795 .diagnostics = &diagnostics,
37963796 }));
37973797 }
37983798
......@@ -3809,7 +3809,7 @@ test "std.zon free on error" {
38093809 \\ .x = "hello",
38103810 \\}
38113811 ,
3812 .errors = &errors,
3812 .diagnostics = &diagnostics,
38133813 }));
38143814
38153815 // Test freeing partially allocated arrays
......@@ -3823,7 +3823,7 @@ test "std.zon free on error" {
38233823 \\ false,
38243824 \\}
38253825 ,
3826 .errors = &errors,
3826 .diagnostics = &diagnostics,
38273827 }));
38283828
38293829 // Test freeing partially allocated slices
......@@ -3837,7 +3837,7 @@ test "std.zon free on error" {
38373837 \\ false,
38383838 \\}
38393839 ,
3840 .errors = &errors,
3840 .diagnostics = &diagnostics,
38413841 }));
38423842
38433843 // We can parse types that can't be freed, as long as they contain no allocations, e.g. untagged
......@@ -3848,7 +3848,7 @@ test "std.zon free on error" {
38483848 .gpa = gpa,
38493849 .arena = arena,
38503850 .source = ".{ .x = 1.5 }",
3851 .errors = &errors,
3851 .diagnostics = &diagnostics,
38523852 })).x,
38533853 );
38543854
......@@ -3859,7 +3859,7 @@ test "std.zon free on error" {
38593859 .gpa = gpa,
38603860 .arena = arena,
38613861 .source = ".{ .x = \"foo\" }",
3862 .errors = &errors,
3862 .diagnostics = &diagnostics,
38633863 });
38643864 try std.testing.expectEqualStrings("foo", result.x);
38653865 }
......@@ -3873,7 +3873,7 @@ test "std.zon vector" {
38733873 var arena_allocator: ArenaAllocator = .init(gpa);
38743874 defer arena_allocator.deinit();
38753875 const arena = arena_allocator.allocator();
3876 var errors: Errors = .empty;
3876 var diagnostics: Diagnostics = .empty;
38773877
38783878 // Passing cases
38793879 try std.testing.expectEqual(
......@@ -3882,7 +3882,7 @@ test "std.zon vector" {
38823882 .gpa = gpa,
38833883 .arena = arena,
38843884 .source = ".{}",
3885 .errors = &errors,
3885 .diagnostics = &diagnostics,
38863886 }),
38873887 );
38883888 try std.testing.expectEqual(
......@@ -3891,7 +3891,7 @@ test "std.zon vector" {
38913891 .gpa = gpa,
38923892 .arena = arena,
38933893 .source = ".{true, false, true}",
3894 .errors = &errors,
3894 .diagnostics = &diagnostics,
38953895 }),
38963896 );
38973897
......@@ -3901,7 +3901,7 @@ test "std.zon vector" {
39013901 .gpa = gpa,
39023902 .arena = arena,
39033903 .source = ".{}",
3904 .errors = &errors,
3904 .diagnostics = &diagnostics,
39053905 }),
39063906 );
39073907 try std.testing.expectEqual(
......@@ -3910,7 +3910,7 @@ test "std.zon vector" {
39103910 .gpa = gpa,
39113911 .arena = arena,
39123912 .source = ".{1.5, 2.5, 3.5}",
3913 .errors = &errors,
3913 .diagnostics = &diagnostics,
39143914 }),
39153915 );
39163916
......@@ -3920,7 +3920,7 @@ test "std.zon vector" {
39203920 .gpa = gpa,
39213921 .arena = arena,
39223922 .source = ".{}",
3923 .errors = &errors,
3923 .diagnostics = &diagnostics,
39243924 }),
39253925 );
39263926 try std.testing.expectEqual(
......@@ -3929,7 +3929,7 @@ test "std.zon vector" {
39293929 .gpa = gpa,
39303930 .arena = arena,
39313931 .source = ".{2, 4, 6}",
3932 .errors = &errors,
3932 .diagnostics = &diagnostics,
39333933 }),
39343934 );
39353935
......@@ -3940,14 +3940,14 @@ test "std.zon vector" {
39403940 .gpa = gpa,
39413941 .arena = arena,
39423942 .source = ".{}",
3943 .errors = &errors,
3943 .diagnostics = &diagnostics,
39443944 }),
39453945 );
39463946 const pointers = try fromSlice(@Vector(3, *const u8), .{
39473947 .gpa = gpa,
39483948 .arena = arena,
39493949 .source = ".{2, 4, 6}",
3950 .errors = &errors,
3950 .diagnostics = &diagnostics,
39513951 });
39523952 try std.testing.expectEqualDeep(@Vector(3, *const u8){ &2, &4, &6 }, pointers);
39533953 }
......@@ -3959,14 +3959,14 @@ test "std.zon vector" {
39593959 .gpa = gpa,
39603960 .arena = arena,
39613961 .source = ".{}",
3962 .errors = &errors,
3962 .diagnostics = &diagnostics,
39633963 }),
39643964 );
39653965 const pointers = try fromSlice(@Vector(3, ?*const u8), .{
39663966 .gpa = gpa,
39673967 .arena = arena,
39683968 .source = ".{2, null, 6}",
3969 .errors = &errors,
3969 .diagnostics = &diagnostics,
39703970 });
39713971 try std.testing.expectEqualDeep(@Vector(3, ?*const u8){ &2, null, &6 }, pointers);
39723972 }
......@@ -3979,13 +3979,13 @@ test "std.zon vector" {
39793979 .gpa = gpa,
39803980 .arena = arena,
39813981 .source = ".{0.5}",
3982 .errors = &errors,
3982 .diagnostics = &diagnostics,
39833983 }),
39843984 );
39853985 try std.testing.expectFmt(
39863986 \\input.zon:1:2: error: expected 2 array elements; found 1
39873987 \\
3988 , "{f}", .{errors.fmt("input.zon")});
3988 , "{f}", .{diagnostics.fmt("input.zon")});
39893989 }
39903990
39913991 // Too many fields
......@@ -3996,13 +3996,13 @@ test "std.zon vector" {
39963996 .gpa = gpa,
39973997 .arena = arena,
39983998 .source = ".{0.5, 1.5, 2.5}",
3999 .errors = &errors,
3999 .diagnostics = &diagnostics,
40004000 }),
40014001 );
40024002 try std.testing.expectFmt(
40034003 \\input.zon:1:13: error: index 2 outside of array of length 2
40044004 \\
4005 , "{f}", .{errors.fmt("input.zon")});
4005 , "{f}", .{diagnostics.fmt("input.zon")});
40064006 }
40074007
40084008 // Wrong type fields
......@@ -4013,13 +4013,13 @@ test "std.zon vector" {
40134013 .gpa = gpa,
40144014 .arena = arena,
40154015 .source = ".{0.5, true, 2.5}",
4016 .errors = &errors,
4016 .diagnostics = &diagnostics,
40174017 }),
40184018 );
40194019 try std.testing.expectFmt(
40204020 \\input.zon:1:8: error: expected type 'f32'
40214021 \\
4022 , "{f}", .{errors.fmt("input.zon")});
4022 , "{f}", .{diagnostics.fmt("input.zon")});
40234023 }
40244024
40254025 // Wrong type
......@@ -4030,13 +4030,13 @@ test "std.zon vector" {
40304030 .gpa = gpa,
40314031 .arena = arena,
40324032 .source = "true",
4033 .errors = &errors,
4033 .diagnostics = &diagnostics,
40344034 }),
40354035 );
40364036 try std.testing.expectFmt(
40374037 \\input.zon:1:1: error: expected type '@Vector(3, u8)'
40384038 \\
4039 , "{f}", .{errors.fmt("input.zon")});
4039 , "{f}", .{diagnostics.fmt("input.zon")});
40404040 }
40414041
40424042 // Elements should get freed on error
......@@ -4047,13 +4047,13 @@ test "std.zon vector" {
40474047 .gpa = gpa,
40484048 .arena = arena,
40494049 .source = ".{1, true, 3}",
4050 .errors = &errors,
4050 .diagnostics = &diagnostics,
40514051 }),
40524052 );
40534053 try std.testing.expectFmt(
40544054 \\input.zon:1:6: error: expected type 'u8'
40554055 \\
4056 , "{f}", .{errors.fmt("input.zon")});
4056 , "{f}", .{diagnostics.fmt("input.zon")});
40574057 }
40584058}
40594059
......@@ -4062,7 +4062,7 @@ test "std.zon add pointers" {
40624062 var arena_allocator: ArenaAllocator = .init(gpa);
40634063 defer arena_allocator.deinit();
40644064 const arena = arena_allocator.allocator();
4065 var errors: Errors = .empty;
4065 var diagnostics: Diagnostics = .empty;
40664066
40674067 // Primitive with varying levels of pointers
40684068 {
......@@ -4070,7 +4070,7 @@ test "std.zon add pointers" {
40704070 .gpa = gpa,
40714071 .arena = arena,
40724072 .source = "10",
4073 .errors = &errors,
4073 .diagnostics = &diagnostics,
40744074 });
40754075 try std.testing.expectEqual(@as(u32, 10), result.*);
40764076 }
......@@ -4080,7 +4080,7 @@ test "std.zon add pointers" {
40804080 .gpa = gpa,
40814081 .arena = arena,
40824082 .source = "10",
4083 .errors = &errors,
4083 .diagnostics = &diagnostics,
40844084 });
40854085 try std.testing.expectEqual(@as(u32, 10), result.*.*);
40864086 }
......@@ -4090,7 +4090,7 @@ test "std.zon add pointers" {
40904090 .gpa = gpa,
40914091 .arena = arena,
40924092 .source = "10",
4093 .errors = &errors,
4093 .diagnostics = &diagnostics,
40944094 });
40954095 try std.testing.expectEqual(@as(u32, 10), result.*.*.*);
40964096 }
......@@ -4101,7 +4101,7 @@ test "std.zon add pointers" {
41014101 .gpa = gpa,
41024102 .arena = arena,
41034103 .source = "10",
4104 .errors = &errors,
4104 .diagnostics = &diagnostics,
41054105 });
41064106 try std.testing.expectEqual(@as(u32, 10), some.?.*);
41074107
......@@ -4109,7 +4109,7 @@ test "std.zon add pointers" {
41094109 .gpa = gpa,
41104110 .arena = arena,
41114111 .source = "null",
4112 .errors = &errors,
4112 .diagnostics = &diagnostics,
41134113 });
41144114 try std.testing.expectEqual(null, none);
41154115 }
......@@ -4119,7 +4119,7 @@ test "std.zon add pointers" {
41194119 .gpa = gpa,
41204120 .arena = arena,
41214121 .source = "10",
4122 .errors = &errors,
4122 .diagnostics = &diagnostics,
41234123 });
41244124 try std.testing.expectEqual(@as(u32, 10), some.*.?);
41254125
......@@ -4127,7 +4127,7 @@ test "std.zon add pointers" {
41274127 .gpa = gpa,
41284128 .arena = arena,
41294129 .source = "null",
4130 .errors = &errors,
4130 .diagnostics = &diagnostics,
41314131 });
41324132 try std.testing.expectEqual(null, none.*);
41334133 }
......@@ -4137,7 +4137,7 @@ test "std.zon add pointers" {
41374137 .gpa = gpa,
41384138 .arena = arena,
41394139 .source = "10",
4140 .errors = &errors,
4140 .diagnostics = &diagnostics,
41414141 });
41424142 try std.testing.expectEqual(@as(u32, 10), some.?.*.*);
41434143
......@@ -4145,7 +4145,7 @@ test "std.zon add pointers" {
41454145 .gpa = gpa,
41464146 .arena = arena,
41474147 .source = "null",
4148 .errors = &errors,
4148 .diagnostics = &diagnostics,
41494149 });
41504150 try std.testing.expectEqual(null, none);
41514151 }
......@@ -4155,7 +4155,7 @@ test "std.zon add pointers" {
41554155 .gpa = gpa,
41564156 .arena = arena,
41574157 .source = "10",
4158 .errors = &errors,
4158 .diagnostics = &diagnostics,
41594159 });
41604160 try std.testing.expectEqual(@as(u32, 10), some.*.?.*);
41614161
......@@ -4163,7 +4163,7 @@ test "std.zon add pointers" {
41634163 .gpa = gpa,
41644164 .arena = arena,
41654165 .source = "null",
4166 .errors = &errors,
4166 .diagnostics = &diagnostics,
41674167 });
41684168 try std.testing.expectEqual(null, none.*);
41694169 }
......@@ -4173,7 +4173,7 @@ test "std.zon add pointers" {
41734173 .gpa = gpa,
41744174 .arena = arena,
41754175 .source = "10",
4176 .errors = &errors,
4176 .diagnostics = &diagnostics,
41774177 });
41784178 try std.testing.expectEqual(@as(u32, 10), some.*.*.?);
41794179
......@@ -4181,7 +4181,7 @@ test "std.zon add pointers" {
41814181 .gpa = gpa,
41824182 .arena = arena,
41834183 .source = "null",
4184 .errors = &errors,
4184 .diagnostics = &diagnostics,
41854185 });
41864186 try std.testing.expectEqual(null, none.*.*);
41874187 }
......@@ -4192,7 +4192,7 @@ test "std.zon add pointers" {
41924192 .gpa = gpa,
41934193 .arena = arena,
41944194 .source = ".{ 1, 2, 3 }",
4195 .errors = &errors,
4195 .diagnostics = &diagnostics,
41964196 });
41974197 try std.testing.expectEqual([3]u8{ 1, 2, 3 }, result.*);
41984198 }
......@@ -4227,7 +4227,7 @@ test "std.zon add pointers" {
42274227 \\ .f2 = null,
42284228 \\}
42294229 ,
4230 .errors = &errors,
4230 .diagnostics = &diagnostics,
42314231 });
42324232
42334233 try std.testing.expectEqualDeep(expected, found.?.*);
......@@ -4241,13 +4241,13 @@ test "std.zon add pointers" {
42414241 .gpa = gpa,
42424242 .arena = arena,
42434243 .source = "true",
4244 .errors = &errors,
4244 .diagnostics = &diagnostics,
42454245 }),
42464246 );
42474247 try std.testing.expectFmt(
42484248 \\input.zon:1:1: error: expected type '?u8'
42494249 \\
4250 , "{f}", .{errors.fmt("input.zon")});
4250 , "{f}", .{diagnostics.fmt("input.zon")});
42514251 }
42524252
42534253 {
......@@ -4257,13 +4257,13 @@ test "std.zon add pointers" {
42574257 .gpa = gpa,
42584258 .arena = arena,
42594259 .source = "true",
4260 .errors = &errors,
4260 .diagnostics = &diagnostics,
42614261 }),
42624262 );
42634263 try std.testing.expectFmt(
42644264 \\input.zon:1:1: error: expected type '?f32'
42654265 \\
4266 , "{f}", .{errors.fmt("input.zon")});
4266 , "{f}", .{diagnostics.fmt("input.zon")});
42674267 }
42684268
42694269 {
......@@ -4273,13 +4273,13 @@ test "std.zon add pointers" {
42734273 .gpa = gpa,
42744274 .arena = arena,
42754275 .source = "true",
4276 .errors = &errors,
4276 .diagnostics = &diagnostics,
42774277 }),
42784278 );
42794279 try std.testing.expectFmt(
42804280 \\input.zon:1:1: error: expected type '?@Vector(3, u8)'
42814281 \\
4282 , "{f}", .{errors.fmt("input.zon")});
4282 , "{f}", .{diagnostics.fmt("input.zon")});
42834283 }
42844284
42854285 {
......@@ -4289,13 +4289,13 @@ test "std.zon add pointers" {
42894289 .gpa = gpa,
42904290 .arena = arena,
42914291 .source = "10",
4292 .errors = &errors,
4292 .diagnostics = &diagnostics,
42934293 }),
42944294 );
42954295 try std.testing.expectFmt(
42964296 \\input.zon:1:1: error: expected type '?bool'
42974297 \\
4298 , "{f}", .{errors.fmt("input.zon")});
4298 , "{f}", .{diagnostics.fmt("input.zon")});
42994299 }
43004300
43014301 {
......@@ -4305,13 +4305,13 @@ test "std.zon add pointers" {
43054305 .gpa = gpa,
43064306 .arena = arena,
43074307 .source = "true",
4308 .errors = &errors,
4308 .diagnostics = &diagnostics,
43094309 }),
43104310 );
43114311 try std.testing.expectFmt(
43124312 \\input.zon:1:1: error: expected optional struct
43134313 \\
4314 , "{f}", .{errors.fmt("input.zon")});
4314 , "{f}", .{diagnostics.fmt("input.zon")});
43154315 }
43164316
43174317 {
......@@ -4321,13 +4321,13 @@ test "std.zon add pointers" {
43214321 .gpa = gpa,
43224322 .arena = arena,
43234323 .source = "true",
4324 .errors = &errors,
4324 .diagnostics = &diagnostics,
43254325 }),
43264326 );
43274327 try std.testing.expectFmt(
43284328 \\input.zon:1:1: error: expected optional tuple
43294329 \\
4330 , "{f}", .{errors.fmt("input.zon")});
4330 , "{f}", .{diagnostics.fmt("input.zon")});
43314331 }
43324332
43334333 {
......@@ -4337,13 +4337,13 @@ test "std.zon add pointers" {
43374337 .gpa = gpa,
43384338 .arena = arena,
43394339 .source = "true",
4340 .errors = &errors,
4340 .diagnostics = &diagnostics,
43414341 }),
43424342 );
43434343 try std.testing.expectFmt(
43444344 \\input.zon:1:1: error: expected optional union
43454345 \\
4346 , "{f}", .{errors.fmt("input.zon")});
4346 , "{f}", .{diagnostics.fmt("input.zon")});
43474347 }
43484348
43494349 {
......@@ -4353,13 +4353,13 @@ test "std.zon add pointers" {
43534353 .gpa = gpa,
43544354 .arena = arena,
43554355 .source = "true",
4356 .errors = &errors,
4356 .diagnostics = &diagnostics,
43574357 }),
43584358 );
43594359 try std.testing.expectFmt(
43604360 \\input.zon:1:1: error: expected optional array
43614361 \\
4362 , "{f}", .{errors.fmt("input.zon")});
4362 , "{f}", .{diagnostics.fmt("input.zon")});
43634363 }
43644364
43654365 {
......@@ -4369,13 +4369,13 @@ test "std.zon add pointers" {
43694369 .gpa = gpa,
43704370 .arena = arena,
43714371 .source = "true",
4372 .errors = &errors,
4372 .diagnostics = &diagnostics,
43734373 }),
43744374 );
43754375 try std.testing.expectFmt(
43764376 \\input.zon:1:1: error: expected optional array
43774377 \\
4378 , "{f}", .{errors.fmt("input.zon")});
4378 , "{f}", .{diagnostics.fmt("input.zon")});
43794379 }
43804380
43814381 {
......@@ -4385,13 +4385,13 @@ test "std.zon add pointers" {
43854385 .gpa = gpa,
43864386 .arena = arena,
43874387 .source = "true",
4388 .errors = &errors,
4388 .diagnostics = &diagnostics,
43894389 }),
43904390 );
43914391 try std.testing.expectFmt(
43924392 \\input.zon:1:1: error: expected optional array
43934393 \\
4394 , "{f}", .{errors.fmt("input.zon")});
4394 , "{f}", .{diagnostics.fmt("input.zon")});
43954395 }
43964396
43974397 {
......@@ -4401,13 +4401,13 @@ test "std.zon add pointers" {
44014401 .gpa = gpa,
44024402 .arena = arena,
44034403 .source = "true",
4404 .errors = &errors,
4404 .diagnostics = &diagnostics,
44054405 }),
44064406 );
44074407 try std.testing.expectFmt(
44084408 \\input.zon:1:1: error: expected optional array
44094409 \\
4410 , "{f}", .{errors.fmt("input.zon")});
4410 , "{f}", .{diagnostics.fmt("input.zon")});
44114411 }
44124412
44134413 {
......@@ -4417,13 +4417,13 @@ test "std.zon add pointers" {
44174417 .gpa = gpa,
44184418 .arena = arena,
44194419 .source = "true",
4420 .errors = &errors,
4420 .diagnostics = &diagnostics,
44214421 }),
44224422 );
44234423 try std.testing.expectFmt(
44244424 \\input.zon:1:1: error: expected optional string
44254425 \\
4426 , "{f}", .{errors.fmt("input.zon")});
4426 , "{f}", .{diagnostics.fmt("input.zon")});
44274427 }
44284428
44294429 {
......@@ -4433,13 +4433,13 @@ test "std.zon add pointers" {
44334433 .gpa = gpa,
44344434 .arena = arena,
44354435 .source = "true",
4436 .errors = &errors,
4436 .diagnostics = &diagnostics,
44374437 }),
44384438 );
44394439 try std.testing.expectFmt(
44404440 \\input.zon:1:1: error: expected optional enum literal
44414441 \\
4442 , "{f}", .{errors.fmt("input.zon")});
4442 , "{f}", .{diagnostics.fmt("input.zon")});
44434443 }
44444444}
44454445
......@@ -4448,7 +4448,7 @@ test "std.zon stop on node" {
44484448 var arena_allocator: ArenaAllocator = .init(gpa);
44494449 defer arena_allocator.deinit();
44504450 const arena = arena_allocator.allocator();
4451 var errors: Errors = .empty;
4451 var diagnostics: Diagnostics = .empty;
44524452
44534453 {
44544454 const Vec2 = struct {
......@@ -4466,7 +4466,7 @@ test "std.zon stop on node" {
44664466 .arena = arena,
44674467 .ast = &ast,
44684468 .zoir = &zoir,
4469 .errors = &errors,
4469 .diagnostics = &diagnostics,
44704470 });
44714471
44724472 try std.testing.expectEqual(result.y, 2.5);
......@@ -4484,7 +4484,7 @@ test "std.zon stop on node" {
44844484 .arena = arena,
44854485 .ast = &ast,
44864486 .zoir = &zoir,
4487 .errors = &errors,
4487 .diagnostics = &diagnostics,
44884488 });
44894489 try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(&zoir));
44904490 }
......@@ -4495,7 +4495,7 @@ test "std.zon no alloc" {
44954495 var arena_allocator: ArenaAllocator = .init(gpa);
44964496 defer arena_allocator.deinit();
44974497 const arena = arena_allocator.allocator();
4498 var errors: Errors = .empty;
4498 var diagnostics: Diagnostics = .empty;
44994499
45004500 try std.testing.expectEqual(
45014501 [3]u8{ 1, 2, 3 },
......@@ -4503,7 +4503,7 @@ test "std.zon no alloc" {
45034503 .gpa = gpa,
45044504 .arena = arena,
45054505 .source = ".{ 1, 2, 3 }",
4506 .errors = &errors,
4506 .diagnostics = &diagnostics,
45074507 }),
45084508 );
45094509
......@@ -4521,64 +4521,17 @@ test "std.zon no alloc" {
45214521 .arena = arena,
45224522 .ast = &ast,
45234523 .zoir = &zoir,
4524 .errors = &errors,
4524 .diagnostics = &diagnostics,
45254525 }),
45264526 );
45274527}
45284528
4529test "std.zon errors without errorsnostics" {
4530 const gpa = std.testing.allocator;
4531 var arena_allocator: ArenaAllocator = .init(gpa);
4532 defer arena_allocator.deinit();
4533 const arena = arena_allocator.allocator();
4534 var errors: Errors = .empty;
4535
4536 const Enum = enum {
4537 foo,
4538 bar,
4539 baz,
4540 };
4541 try std.testing.expectError(error.ParseZon, fromSlice(Enum, .{
4542 .gpa = gpa,
4543 .arena = arena,
4544 .source = ".nothing",
4545 .errors = &errors,
4546 }));
4547
4548 const Struct = struct {
4549 name: []const u8,
4550 };
4551 try std.testing.expectError(error.ParseZon, fromSlice(Struct, .{
4552 .gpa = gpa,
4553 .arena = arena,
4554 .source = ".{ .name = \"Alice\", .age = 25 }",
4555 .errors = &errors,
4556 }));
4557
4558 const Union = union(enum) {
4559 x,
4560 y: u32,
4561 };
4562 try std.testing.expectError(error.ParseZon, fromSlice(Union, .{
4563 .gpa = gpa,
4564 .arena = arena,
4565 .source = ".a",
4566 .errors = &errors,
4567 }));
4568 try std.testing.expectError(error.ParseZon, fromSlice(Union, .{
4569 .gpa = gpa,
4570 .arena = arena,
4571 .source = ".{ .b = 8 }",
4572 .errors = &errors,
4573 }));
4574}
4575
45764529test "std.zon aligned pointers" {
45774530 const gpa = std.testing.allocator;
45784531 var arena_allocator: ArenaAllocator = .init(gpa);
45794532 defer arena_allocator.deinit();
45804533 const arena = arena_allocator.allocator();
4581 var errors: Errors = .empty;
4534 var diagnostics: Diagnostics = .empty;
45824535
45834536 const n: u8 align(8) = 10;
45844537 const Foo = struct {
......@@ -4592,7 +4545,7 @@ test "std.zon aligned pointers" {
45924545 .gpa = gpa,
45934546 .arena = arena,
45944547 .source = ".{ .inner = 10 }",
4595 .errors = &errors,
4548 .diagnostics = &diagnostics,
45964549 });
45974550 try std.testing.expectEqualDeep(expected.inner, found.inner);
45984551}
......@@ -4602,7 +4555,7 @@ test "std.zon update basic" {
46024555 var arena_allocator: ArenaAllocator = .init(gpa);
46034556 defer arena_allocator.deinit();
46044557 const arena = arena_allocator.allocator();
4605 var errors: Errors = .empty;
4558 var diagnostics: Diagnostics = .empty;
46064559
46074560 const Vector = struct { x: f32, y: f32, z: f32 };
46084561 const MyStruct = struct {
......@@ -4638,7 +4591,7 @@ test "std.zon update basic" {
46384591 .gpa = gpa,
46394592 .arena = arena,
46404593 .source = ".{}",
4641 .errors = &errors,
4594 .diagnostics = &diagnostics,
46424595 });
46434596 try std.testing.expectEqualDeep(expected, found);
46444597
......@@ -4646,7 +4599,7 @@ test "std.zon update basic" {
46464599 .gpa = gpa,
46474600 .arena = arena,
46484601 .source = ".{ .bar = false }",
4649 .errors = &errors,
4602 .diagnostics = &diagnostics,
46504603 });
46514604 expected.bar = false;
46524605 try std.testing.expectEqualDeep(expected, found);
......@@ -4655,7 +4608,7 @@ test "std.zon update basic" {
46554608 .gpa = gpa,
46564609 .arena = arena,
46574610 .source = ".{ .baz = .{ .a = .{ 2, 4 } } }",
4658 .errors = &errors,
4611 .diagnostics = &diagnostics,
46594612 });
46604613 expected.baz.a[0] = 2;
46614614 expected.baz.a[1] = 4;
......@@ -4665,7 +4618,7 @@ test "std.zon update basic" {
46654618 .gpa = gpa,
46664619 .arena = arena,
46674620 .source = ".{ .foo = 11, .baz = .{ .b = .d } }",
4668 .errors = &errors,
4621 .diagnostics = &diagnostics,
46694622 });
46704623 expected.foo = 11;
46714624 expected.baz.b = .d;
......@@ -4675,7 +4628,7 @@ test "std.zon update basic" {
46754628 .gpa = gpa,
46764629 .arena = arena,
46774630 .source = ".{ .optional = 10 }",
4678 .errors = &errors,
4631 .diagnostics = &diagnostics,
46794632 });
46804633 expected.optional = 10;
46814634 try std.testing.expectEqualDeep(expected, found);
......@@ -4684,7 +4637,7 @@ test "std.zon update basic" {
46844637 .gpa = gpa,
46854638 .arena = arena,
46864639 .source = ".{ .optional = null }",
4687 .errors = &errors,
4640 .diagnostics = &diagnostics,
46884641 });
46894642 expected.optional = null;
46904643 try std.testing.expectEqualDeep(expected, found);
......@@ -4693,7 +4646,7 @@ test "std.zon update basic" {
46934646 .gpa = gpa,
46944647 .arena = arena,
46954648 .source = ".{ .ptr = .{ .x = 10, .y = 20, .z = 30 } }",
4696 .errors = &errors,
4649 .diagnostics = &diagnostics,
46974650 });
46984651 expected.ptr.x = 10;
46994652 expected.ptr.y = 20;
......@@ -4704,7 +4657,7 @@ test "std.zon update basic" {
47044657 .gpa = gpa,
47054658 .arena = arena,
47064659 .source = ".{ .str = \"foo\" }",
4707 .errors = &errors,
4660 .diagnostics = &diagnostics,
47084661 });
47094662 expected.str = "foo";
47104663 try std.testing.expectEqualDeep(expected, found);
......@@ -4715,7 +4668,7 @@ test "std.zon update optionals" {
47154668 var arena_allocator: ArenaAllocator = .init(gpa);
47164669 defer arena_allocator.deinit();
47174670 const arena = arena_allocator.allocator();
4718 var errors: Errors = .empty;
4671 var diagnostics: Diagnostics = .empty;
47194672
47204673 const MyStruct = struct {
47214674 foo: ?struct { bar: u32 = 1, baz: u32 = 2, qux: u32 },
......@@ -4729,7 +4682,7 @@ test "std.zon update optionals" {
47294682 .gpa = gpa,
47304683 .arena = arena,
47314684 .source = ".{ .foo = .{ .qux = 3 } }",
4732 .errors = &errors,
4685 .diagnostics = &diagnostics,
47334686 });
47344687 expected.foo = .{ .qux = 3 };
47354688 try std.testing.expectEqual(expected, found);
......@@ -4742,12 +4695,12 @@ test "std.zon update optionals" {
47424695 .gpa = gpa,
47434696 .arena = arena,
47444697 .source = ".{ .foo = .{} }",
4745 .errors = &errors,
4698 .diagnostics = &diagnostics,
47464699 }));
47474700 try std.testing.expectFmt(
47484701 \\input.zon:1:12: error: missing required field qux
47494702 \\
4750 , "{f}", .{errors.fmt("input.zon")});
4703 , "{f}", .{diagnostics.fmt("input.zon")});
47514704 }
47524705
47534706 // Updating an optional that starts out non-null should preserve any values we leave off. It's
......@@ -4761,7 +4714,7 @@ test "std.zon update optionals" {
47614714 .gpa = gpa,
47624715 .arena = arena,
47634716 .source = ".{ .foo = .{ .baz = 200 } }",
4764 .errors = &errors,
4717 .diagnostics = &diagnostics,
47654718 });
47664719 expected.foo.?.baz = 200;
47674720 try std.testing.expectEqual(expected, found);
......@@ -4773,7 +4726,7 @@ test "std.zon update optional pointers" {
47734726 var arena_allocator: ArenaAllocator = .init(gpa);
47744727 defer arena_allocator.deinit();
47754728 const arena = arena_allocator.allocator();
4776 var errors: Errors = .empty;
4729 var diagnostics: Diagnostics = .empty;
47774730
47784731 const MyStruct = struct {
47794732 foo: ?*const struct { bar: u32 = 1, baz: u32 = 2, qux: u32 },
......@@ -4787,7 +4740,7 @@ test "std.zon update optional pointers" {
47874740 .gpa = gpa,
47884741 .arena = arena,
47894742 .source = ".{ .foo = .{ .qux = 3 } }",
4790 .errors = &errors,
4743 .diagnostics = &diagnostics,
47914744 });
47924745 expected.foo = &.{ .qux = 3 };
47934746 try std.testing.expectEqualDeep(expected, found);
......@@ -4799,7 +4752,7 @@ test "std.zon update pointers" {
47994752 var arena_allocator: ArenaAllocator = .init(gpa);
48004753 defer arena_allocator.deinit();
48014754 const arena = arena_allocator.allocator();
4802 var errors: Errors = .empty;
4755 var diagnostics: Diagnostics = .empty;
48034756
48044757 // Updating a pointer should leave fields we don't specify unchanged
48054758 {
......@@ -4813,7 +4766,7 @@ test "std.zon update pointers" {
48134766 .gpa = gpa,
48144767 .arena = arena,
48154768 .source = ".{ .foo = .{ .bar = 100 } }",
4816 .errors = &errors,
4769 .diagnostics = &diagnostics,
48174770 });
48184771 expected.foo.bar = 100;
48194772 try std.testing.expectEqualDeep(expected, found);
......@@ -4830,7 +4783,7 @@ test "std.zon update pointers" {
48304783 .gpa = gpa,
48314784 .arena = arena,
48324785 .source = ".{ .foo = .{ .bar = 100 } }",
4833 .errors = &errors,
4786 .diagnostics = &diagnostics,
48344787 });
48354788 expected.foo = &.{ .bar = 100, .baz = 20, .qux = 3 };
48364789 try std.testing.expectEqualDeep(expected, found);
......@@ -4842,7 +4795,7 @@ test "std.zon update unions" {
48424795 var arena_allocator: ArenaAllocator = .init(gpa);
48434796 defer arena_allocator.deinit();
48444797 const arena = arena_allocator.allocator();
4845 var errors: Errors = .empty;
4798 var diagnostics: Diagnostics = .empty;
48464799
48474800 const MyUnion = union(enum) {
48484801 none: void,
......@@ -4857,7 +4810,7 @@ test "std.zon update unions" {
48574810 .gpa = gpa,
48584811 .arena = arena,
48594812 .source = ".{ .foo = .{ .qux = 3 } }",
4860 .errors = &errors,
4813 .diagnostics = &diagnostics,
48614814 });
48624815 expected = .{ .foo = .{ .qux = 3 } };
48634816 try std.testing.expectEqual(expected, found);
......@@ -4870,12 +4823,12 @@ test "std.zon update unions" {
48704823 .gpa = gpa,
48714824 .arena = arena,
48724825 .source = ".{ .foo = .{} }",
4873 .errors = &errors,
4826 .diagnostics = &diagnostics,
48744827 }));
48754828 try std.testing.expectFmt(
48764829 \\input.zon:1:12: error: missing required field qux
48774830 \\
4878 , "{f}", .{errors.fmt("input.zon")});
4831 , "{f}", .{diagnostics.fmt("input.zon")});
48794832 }
48804833
48814834 // Updating a union should preseve any sub-fields that we left off. It's also okay to leave off
......@@ -4889,7 +4842,7 @@ test "std.zon update unions" {
48894842 .gpa = gpa,
48904843 .arena = arena,
48914844 .source = ".{ .foo = .{ .baz = 200 } }",
4892 .errors = &errors,
4845 .diagnostics = &diagnostics,
48934846 });
48944847 expected.foo.baz = 200;
48954848 try std.testing.expectEqual(expected, found);
......@@ -4904,7 +4857,7 @@ test "std.zon variants" {
49044857 var arena_allocator: ArenaAllocator = .init(gpa);
49054858 defer arena_allocator.deinit();
49064859 const arena = arena_allocator.allocator();
4907 var errors: Errors = .empty;
4860 var diagnostics: Diagnostics = .empty;
49084861
49094862 const Struct = struct { a: u32, b: u32 };
49104863 const start: Struct = .{ .a = 10, .b = 20 };
......@@ -4922,7 +4875,7 @@ test "std.zon variants" {
49224875 .gpa = gpa,
49234876 .arena = arena,
49244877 .source = ".{ .a = 100 }",
4925 .errors = &errors,
4878 .diagnostics = &diagnostics,
49264879 });
49274880 try std.testing.expectEqual(end, curr);
49284881
......@@ -4931,7 +4884,7 @@ test "std.zon variants" {
49314884 .gpa = gpa,
49324885 .arena = arena,
49334886 .source = ".{ .a = 100 }",
4934 .errors = &errors,
4887 .diagnostics = &diagnostics,
49354888 });
49364889 try std.testing.expectEqual(end, curr);
49374890
......@@ -4940,7 +4893,7 @@ test "std.zon variants" {
49404893 .arena = arena,
49414894 .ast = &ast,
49424895 .zoir = &zoir,
4943 .errors = &errors,
4896 .diagnostics = &diagnostics,
49444897 });
49454898 try std.testing.expectEqual(end, curr);
49464899
......@@ -4949,7 +4902,7 @@ test "std.zon variants" {
49494902 .arena = arena,
49504903 .ast = &ast,
49514904 .zoir = &zoir,
4952 .errors = &errors,
4905 .diagnostics = &diagnostics,
49534906 });
49544907 try std.testing.expectEqual(end, curr);
49554908 }
......@@ -4967,7 +4920,7 @@ test "std.zon variants" {
49674920 .gpa = gpa,
49684921 .arena = arena,
49694922 .source = ".{ .a = 100, .b = 20 }",
4970 .errors = &errors,
4923 .diagnostics = &diagnostics,
49714924 }),
49724925 );
49734926 try std.testing.expectEqual(
......@@ -4976,7 +4929,7 @@ test "std.zon variants" {
49764929 .gpa = gpa,
49774930 .arena = arena,
49784931 .source = ".{ .a = 100, .b = 20 }",
4979 .errors = &errors,
4932 .diagnostics = &diagnostics,
49804933 }),
49814934 );
49824935 try std.testing.expectEqual(
......@@ -4984,7 +4937,7 @@ test "std.zon variants" {
49844937 .arena = arena,
49854938 .ast = &ast,
49864939 .zoir = &zoir,
4987 .errors = &errors,
4940 .diagnostics = &diagnostics,
49884941 }),
49894942 end,
49904943 );
......@@ -4993,7 +4946,7 @@ test "std.zon variants" {
49934946 .arena = arena,
49944947 .ast = &ast,
49954948 .zoir = &zoir,
4996 .errors = &errors,
4949 .diagnostics = &diagnostics,
49974950 }),
49984951 end,
49994952 );
......@@ -5001,5 +4954,5 @@ test "std.zon variants" {
50014954}
50024955
50034956test {
5004 _ = Errors;
4957 _ = Diagnostics;
50054958}