authorgravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-07-20 00:14:55-07:00
committergravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-09-26 12:35:38-07:00
log6d21ffce6ee79bba8238db9f8012579f3cec7e57
tree13925c886d0f889de7ec1c3a4a06a8c248614fa2
parenta5bfa7aa453f2a061791501339044db452b93df5

Use clearer conventions for diagnostics


1 files changed, 517 insertions(+), 516 deletions(-)

lib/std/zon/parse.zig+517-516
......@@ -4,7 +4,7 @@
44//! * `fromZoir`/`fromZoirAlloc`
55//!
66//! To update an existing values, see the `updateFrom*` variants. To get human readable errors, use
7//! the `diag` option. For lower level control over parsing, see `std.zig.Zoir`. For importing ZON
7//! the `errors` option. For lower level control over parsing, see `std.zig.Zoir`. For importing ZON
88//! at compile time, use `@import`.
99
1010const std = @import("std");
......@@ -23,6 +23,7 @@ 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.
2627pub const Error = struct {
2728 msg: []const u8,
2829 loc: Ast.Location,
......@@ -90,20 +91,20 @@ pub const Error = struct {
9091 };
9192};
9293
93/// Human readable information about the success or failure of a parse.
94pub const Diagnostics = struct {
94/// Errors encountered while parsing ZON.
95pub const Errors = struct {
9596 arena: Allocator,
96 compile_errors: std.ArrayList(Error),
97 list: std.ArrayList(Error),
9798
9899 pub fn init(arena: Allocator) @This() {
99100 return .{
100101 .arena = arena,
101 .compile_errors = .empty,
102 .list = .empty,
102103 };
103104 }
104105
105106 pub fn format(self: *const @This(), w: *std.Io.Writer) std.Io.Writer.Error!void {
106 for (self.compile_errors.items) |e| {
107 for (self.list.items) |e| {
107108 try w.print("{d}:{d}: error: {s}\n", .{
108109 e.loc.line + 1,
109110 e.loc.column + 1,
......@@ -121,17 +122,17 @@ pub const Diagnostics = struct {
121122 }
122123
123124 pub fn clear(self: *@This()) void {
124 self.compile_errors.clearRetainingCapacity();
125 self.errors.clearRetainingCapacity();
125126 }
126127};
127128
128129pub const FromSliceOptions = struct {
129130 /// Used for scratch allocations.
130131 gpa: Allocator,
131 /// The ZON source.
132 /// The ZON source to parse.
132133 source: [:0]const u8,
133 /// Write human readable error messages here.
134 diag: ?*Diagnostics,
134 /// If non-null, any errors encountered are appended here.
135 errors: ?*Errors,
135136 /// If true, unknown fields do not error.
136137 ignore_unknown_fields: bool = false,
137138};
......@@ -142,7 +143,7 @@ pub const FromSliceOptions = struct {
142143/// invalid or can not be deserialized into type `T`.
143144///
144145/// When the parser returns `error.ParseZon`, it will also store a human readable explanation in
145/// `diag` if non null.
146/// `errors` if non null.
146147///
147148/// Asserts at compile time that the result type doesn't contain pointers. As such, the result
148149/// doesn't need to be freed.
......@@ -154,7 +155,7 @@ pub fn fromSlice(T: type, options: FromSliceOptions) error{ OutOfMemory, ParseZo
154155 .gpa = options.gpa,
155156 .arena = .failing,
156157 .source = options.source,
157 .diag = options.diag,
158 .errors = options.errors,
158159 .ignore_unknown_fields = options.ignore_unknown_fields,
159160 });
160161}
......@@ -172,7 +173,7 @@ pub fn updateFromSlice(
172173 .gpa = options.gpa,
173174 .arena = .failing,
174175 .source = options.source,
175 .diag = options.diag,
176 .errors = options.errors,
176177 .ignore_unknown_fields = options.ignore_unknown_fields,
177178 });
178179}
......@@ -182,10 +183,10 @@ pub const FromSliceAllocOptions = struct {
182183 gpa: Allocator,
183184 /// Owns the result.
184185 arena: Allocator,
185 /// The ZON source.
186 /// The ZON source to parse.
186187 source: [:0]const u8,
187 /// Write human readable error messages here.
188 diag: ?*Diagnostics,
188 /// If non-null, any errors encountered are appended here.
189 errors: ?*Errors,
189190 /// If true, unknown fields do not error.
190191 ignore_unknown_fields: bool = false,
191192};
......@@ -198,7 +199,7 @@ pub fn fromSliceAlloc(T: type, options: FromSliceAllocOptions) error{ OutOfMemor
198199 .gpa = options.gpa,
199200 .arena = options.arena,
200201 .source = options.source,
201 .diag = options.diag,
202 .errors = options.errors,
202203 .ignore_unknown_fields = options.ignore_unknown_fields,
203204 .initialized = false,
204205 });
......@@ -215,7 +216,7 @@ pub fn updateFromSliceAlloc(
215216 .gpa = options.gpa,
216217 .arena = options.arena,
217218 .source = options.source,
218 .diag = options.diag,
219 .errors = options.errors,
219220 .ignore_unknown_fields = options.ignore_unknown_fields,
220221 .initialized = true,
221222 });
......@@ -225,7 +226,7 @@ const ParseSliceAllocOptions = struct {
225226 gpa: Allocator,
226227 arena: Allocator,
227228 source: [:0]const u8,
228 diag: ?*Diagnostics,
229 errors: ?*Errors,
229230 ignore_unknown_fields: bool,
230231 initialized: bool,
231232};
......@@ -246,7 +247,7 @@ fn parseSliceAlloc(
246247 .ast = &ast,
247248 .zoir = &zoir,
248249 .node = .root,
249 .diag = options.diag,
250 .errors = options.errors,
250251 .ignore_unknown_fields = options.ignore_unknown_fields,
251252 .initialized = options.initialized,
252253 });
......@@ -259,8 +260,8 @@ pub const FromZoirOptions = struct {
259260 zoir: *const Zoir,
260261 /// The node to start parsing at.
261262 node: Zoir.Node.Index = .root,
262 /// Write human readable error messages here.
263 diag: ?*Diagnostics,
263 /// If non-null, any errors encountered are appended here.
264 errors: ?*Errors,
264265 /// If true, unknown fields do not error.
265266 ignore_unknown_fields: bool = false,
266267};
......@@ -273,7 +274,7 @@ pub fn fromZoir(T: type, options: FromZoirOptions) error{ParseZon}!T {
273274 .ast = options.ast,
274275 .zoir = options.zoir,
275276 .node = options.node,
276 .diag = options.diag,
277 .errors = options.errors,
277278 .ignore_unknown_fields = options.ignore_unknown_fields,
278279 }) catch |err| switch (err) {
279280 error.OutOfMemory => unreachable, // Checked by comptime assertion above
......@@ -293,7 +294,7 @@ pub fn updateFromZoir(
293294 .ast = options.ast,
294295 .zoir = options.zoir,
295296 .node = options.node,
296 .diag = options.diag,
297 .errors = options.errors,
297298 .ignore_unknown_fields = options.ignore_unknown_fields,
298299 }) catch |err| switch (err) {
299300 error.OutOfMemory => unreachable, // Checked by comptime assertion above
......@@ -310,8 +311,8 @@ pub const FromZoirAllocOptions = struct {
310311 zoir: *const Zoir,
311312 /// The node to start parsing at.
312313 node: Zoir.Node.Index = .root,
313 /// Write human readable error messages here.
314 diag: ?*Diagnostics,
314 /// If non-null, any errors encountered are appended here.
315 errors: ?*Errors,
315316 /// If true, unknown fields do not error.
316317 ignore_unknown_fields: bool = false,
317318};
......@@ -324,7 +325,7 @@ pub fn fromZoirAlloc(T: type, options: FromZoirAllocOptions) error{ OutOfMemory,
324325 .ast = options.ast,
325326 .zoir = options.zoir,
326327 .node = options.node,
327 .diag = options.diag,
328 .errors = options.errors,
328329 .ignore_unknown_fields = options.ignore_unknown_fields,
329330 .initialized = false,
330331 });
......@@ -342,7 +343,7 @@ pub fn updateFromZoirAlloc(
342343 .ast = options.ast,
343344 .zoir = options.zoir,
344345 .node = options.node,
345 .diag = options.diag,
346 .errors = options.errors,
346347 .ignore_unknown_fields = options.ignore_unknown_fields,
347348 .initialized = true,
348349 });
......@@ -353,7 +354,7 @@ const ParseZoirAllocOptions = struct {
353354 ast: *const Ast,
354355 zoir: *const Zoir,
355356 node: Zoir.Node.Index,
356 diag: ?*Diagnostics,
357 errors: ?*Errors,
357358 ignore_unknown_fields: bool,
358359 initialized: bool,
359360};
......@@ -366,21 +367,21 @@ fn parseZoirAlloc(
366367 comptime assert(canParseType(T));
367368
368369 if (options.zoir.hasCompileErrors()) {
369 if (options.diag) |s| {
370 if (options.errors) |errors| {
370371 for (options.zoir.compile_errors) |e| {
371372 var notes: std.ArrayList(Error.Note) = .empty;
372373 for (e.getNotes(options.zoir)) |note| {
373 try notes.append(s.arena, .init(options.ast, .{
374 .msg = try s.arena.dupe(u8, note.msg.get(options.zoir)),
374 try notes.append(errors.arena, .init(options.ast, .{
375 .msg = try errors.arena.dupe(u8, note.msg.get(options.zoir)),
375376 .token = note.token,
376377 .node_or_offset = note.node_or_offset,
377378 }));
378379 }
379 try s.compile_errors.append(s.arena, .init(options.ast, .{
380 .msg = try s.arena.dupe(u8, e.msg.get(options.zoir)),
380 try errors.list.append(errors.arena, .init(options.ast, .{
381 .msg = try errors.arena.dupe(u8, e.msg.get(options.zoir)),
381382 .token = e.token,
382383 .node_or_offset = e.node_or_offset,
383 .notes = try notes.toOwnedSlice(s.arena),
384 .notes = try notes.toOwnedSlice(errors.arena),
384385 }));
385386 }
386387 }
......@@ -392,7 +393,7 @@ fn parseZoirAlloc(
392393 .ast = options.ast,
393394 .zoir = options.zoir,
394395 .ignore_unknown_fields = options.ignore_unknown_fields,
395 .diag = options.diag,
396 .errors = options.errors,
396397 };
397398
398399 try parser.parseExprInto(options.node, value, options.initialized);
......@@ -423,7 +424,7 @@ const Parser = struct {
423424 arena: Allocator,
424425 ast: *const Ast,
425426 zoir: *const Zoir,
426 diag: ?*Diagnostics,
427 errors: ?*Errors,
427428 ignore_unknown_fields: bool,
428429
429430 const ParseExprError = error{ ParseZon, OutOfMemory };
......@@ -997,10 +998,10 @@ const Parser = struct {
997998 ) error{ OutOfMemory, ParseZon } {
998999 @branchHint(.cold);
9991000 comptime assert(args.len > 0);
1000 if (self.diag) |s| try s.compile_errors.append(s.arena, .init(self.ast, .{
1001 if (self.errors) |errors| try errors.list.append(errors.arena, .init(self.ast, .{
10011002 .token = .fromToken(token),
10021003 .node_or_offset = offset,
1003 .msg = try std.fmt.allocPrint(s.arena, fmt, args),
1004 .msg = try std.fmt.allocPrint(errors.arena, fmt, args),
10041005 .notes = notes,
10051006 }));
10061007 return error.ParseZon;
......@@ -1022,7 +1023,7 @@ const Parser = struct {
10221023 failure: Error,
10231024 ) error{ OutOfMemory, ParseZon } {
10241025 @branchHint(.cold);
1025 if (self.diag) |s| try s.compile_errors.append(s.arena, failure);
1026 if (self.errors) |errors| try errors.list.append(errors.arena, failure);
10261027 return error.ParseZon;
10271028 }
10281029
......@@ -1059,7 +1060,7 @@ const Parser = struct {
10591060 name: []const u8,
10601061 ) error{ OutOfMemory, ParseZon } {
10611062 @branchHint(.cold);
1062 const diag = self.diag orelse return error.ParseZon;
1063 const errors = self.errors orelse return error.ParseZon;
10631064 const token = if (field) |f| b: {
10641065 var buf: [2]Ast.Node.Index = undefined;
10651066 const struct_init = self.ast.fullStructInit(&buf, node.getAstNode(self.zoir)).?;
......@@ -1070,13 +1071,13 @@ const Parser = struct {
10701071 inline .@"struct", .@"union", .@"enum" => |info| {
10711072 var notes: std.ArrayList(Error.Note) = .empty;
10721073 if (info.field_names.len == 0) {
1073 try notes.append(diag.arena, .init(self.ast, .{
1074 try notes.append(errors.arena, .init(self.ast, .{
10741075 .token = .fromToken(token),
10751076 .node_or_offset = 0,
10761077 .msg = "none expected",
10771078 }));
10781079 } else {
1079 var aw: std.Io.Writer.Allocating = .init(diag.arena);
1080 var aw: std.Io.Writer.Allocating = .init(errors.arena);
10801081 aw.writer.writeAll("supported: ") catch return error.OutOfMemory;
10811082 inline for (info.field_names, 0..) |field_name, i| {
10821083 if (i != 0) aw.writer.writeAll(", ") catch return error.OutOfMemory;
......@@ -1085,7 +1086,7 @@ const Parser = struct {
10851086 .allow_underscore = true,
10861087 })}) catch return error.OutOfMemory;
10871088 }
1088 try notes.append(diag.arena, .init(self.ast, .{
1089 try notes.append(errors.arena, .init(self.ast, .{
10891090 .token = .fromToken(token),
10901091 .node_or_offset = 0,
10911092 .msg = try aw.toOwnedSlice(),
......@@ -1096,7 +1097,7 @@ const Parser = struct {
10961097 0,
10971098 "unexpected {s} '{s}'",
10981099 .{ item_kind, name },
1099 try notes.toOwnedSlice(diag.arena),
1100 try notes.toOwnedSlice(errors.arena),
11001101 );
11011102 },
11021103 else => comptime unreachable,
......@@ -1112,7 +1113,7 @@ const Parser = struct {
11121113 field: usize,
11131114 ) error{ OutOfMemory, ParseZon } {
11141115 @branchHint(.cold);
1115 if (self.diag == null) return error.ParseZon;
1116 if (self.errors == null) return error.ParseZon;
11161117 const ast_node = node.getAstNode(self.zoir);
11171118 var buf: [2]Ast.Node.Index = undefined;
11181119 const token = if (self.ast.fullStructInit(&buf, ast_node)) |struct_init| b: {
......@@ -1293,16 +1294,16 @@ test "std.zon ast errors" {
12931294 var arena_allocator: ArenaAllocator = .init(gpa);
12941295 defer arena_allocator.deinit();
12951296 const arena = arena_allocator.allocator();
1296 var diag: Diagnostics = .init(arena);
1297 var errors: Errors = .init(arena);
12971298 try std.testing.expectError(
12981299 error.ParseZon,
12991300 fromSlice(struct {}, .{
13001301 .gpa = gpa,
13011302 .source = ".{.x = 1 .y = 2}",
1302 .diag = &diag,
1303 .errors = &errors,
13031304 }),
13041305 );
1305 try std.testing.expectFmt("1:13: error: expected ',' after initializer\n", "{f}", .{diag});
1306 try std.testing.expectFmt("1:13: error: expected ',' after initializer\n", "{f}", .{errors});
13061307}
13071308
13081309test "std.zon comments" {
......@@ -1318,11 +1319,11 @@ test "std.zon comments" {
13181319 \\10 // comment
13191320 \\// comment
13201321 ,
1321 .diag = null,
1322 .errors = null,
13221323 }));
13231324
13241325 {
1325 var diag: Diagnostics = .init(arena);
1326 var errors: Errors = .init(arena);
13261327 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
13271328 .gpa = gpa,
13281329 .source =
......@@ -1330,12 +1331,12 @@ test "std.zon comments" {
13301331 \\10 // comment
13311332 \\// comment
13321333 ,
1333 .diag = &diag,
1334 .errors = &errors,
13341335 }));
13351336 try std.testing.expectFmt(
13361337 "1:1: error: expected expression, found 'a document comment'\n",
13371338 "{f}",
1338 .{diag},
1339 .{errors},
13391340 );
13401341 }
13411342}
......@@ -1345,14 +1346,14 @@ test "std.zon failure/oom formatting" {
13451346 var arena_allocator: ArenaAllocator = .init(gpa);
13461347 defer arena_allocator.deinit();
13471348 const arena = arena_allocator.allocator();
1348 var diag: Diagnostics = .init(arena);
1349 var errors: Errors = .init(arena);
13491350 try std.testing.expectError(error.OutOfMemory, fromSliceAlloc([]const u8, .{
13501351 .gpa = .failing,
13511352 .arena = arena,
13521353 .source = "\"foo\"",
1353 .diag = &diag,
1354 .errors = &errors,
13541355 }));
1355 try std.testing.expectFmt("", "{f}", .{diag});
1356 try std.testing.expectFmt("", "{f}", .{errors});
13561357}
13571358
13581359test "std.zon fromSliceAlloc syntax error" {
......@@ -1362,7 +1363,7 @@ test "std.zon fromSliceAlloc syntax error" {
13621363 fromSlice(u8, .{
13631364 .gpa = gpa,
13641365 .source = ".{",
1365 .diag = null,
1366 .errors = null,
13661367 }),
13671368 );
13681369}
......@@ -1378,13 +1379,13 @@ test "std.zon optional" {
13781379 const none = try fromSlice(?u32, .{
13791380 .gpa = gpa,
13801381 .source = "null",
1381 .diag = null,
1382 .errors = null,
13821383 });
13831384 try std.testing.expect(none == null);
13841385 const some = try fromSlice(?u32, .{
13851386 .gpa = gpa,
13861387 .source = "1",
1387 .diag = null,
1388 .errors = null,
13881389 });
13891390 try std.testing.expect(some.? == 1);
13901391 }
......@@ -1395,14 +1396,14 @@ test "std.zon optional" {
13951396 .gpa = gpa,
13961397 .arena = arena,
13971398 .source = "null",
1398 .diag = null,
1399 .errors = null,
13991400 });
14001401 try std.testing.expect(none == null);
14011402 const some = try fromSliceAlloc(?[]const u8, .{
14021403 .gpa = gpa,
14031404 .arena = arena,
14041405 .source = "\"foo\"",
1405 .diag = null,
1406 .errors = null,
14061407 });
14071408 try std.testing.expectEqualStrings("foo", some.?);
14081409 }
......@@ -1422,38 +1423,38 @@ test "std.zon unions" {
14221423 const tagged_x = try fromSlice(Tagged, .{
14231424 .gpa = gpa,
14241425 .source = ".{.x = 1.5}",
1425 .diag = null,
1426 .errors = null,
14261427 });
14271428 try std.testing.expectEqual(Tagged{ .x = 1.5 }, tagged_x);
14281429 const tagged_y = try fromSlice(Tagged, .{
14291430 .gpa = gpa,
14301431 .source = ".{.@\"y y\" = true}",
1431 .diag = null,
1432 .errors = null,
14321433 });
14331434 try std.testing.expectEqual(Tagged{ .@"y y" = true }, tagged_y);
14341435 const tagged_z_shorthand = try fromSlice(Tagged, .{
14351436 .gpa = gpa,
14361437 .source = ".z",
1437 .diag = null,
1438 .errors = null,
14381439 });
14391440 try std.testing.expectEqual(@as(Tagged, .z), tagged_z_shorthand);
14401441 const tagged_zz_shorthand = try fromSlice(Tagged, .{
14411442 .gpa = gpa,
14421443 .source = ".@\"z z\"",
1443 .diag = null,
1444 .errors = null,
14441445 });
14451446 try std.testing.expectEqual(@as(Tagged, .@"z z"), tagged_zz_shorthand);
14461447
14471448 const untagged_x = try fromSlice(Untagged, .{
14481449 .gpa = gpa,
14491450 .source = ".{.x = 1.5}",
1450 .diag = null,
1451 .errors = null,
14511452 });
14521453 try std.testing.expect(untagged_x.x == 1.5);
14531454 const untagged_y = try fromSlice(Untagged, .{
14541455 .gpa = gpa,
14551456 .source = ".{.@\"y y\" = true}",
1456 .diag = null,
1457 .errors = null,
14571458 });
14581459 try std.testing.expect(untagged_y.@"y y");
14591460 }
......@@ -1466,7 +1467,7 @@ test "std.zon unions" {
14661467 .gpa = gpa,
14671468 .arena = arena,
14681469 .source = ".{.baz = false}",
1469 .diag = null,
1470 .errors = null,
14701471 });
14711472 try std.testing.expectEqual(Union{ .baz = false }, noalloc);
14721473
......@@ -1474,7 +1475,7 @@ test "std.zon unions" {
14741475 .gpa = gpa,
14751476 .arena = arena,
14761477 .source = ".{.bar = \"qux\"}",
1477 .diag = null,
1478 .errors = null,
14781479 });
14791480 try std.testing.expectEqualDeep(Union{ .bar = "qux" }, alloc);
14801481 }
......@@ -1482,14 +1483,14 @@ test "std.zon unions" {
14821483 // Unknown field
14831484 {
14841485 const Union = union { x: f32, y: f32 };
1485 var diag: Diagnostics = .init(arena);
1486 var errors: Errors = .init(arena);
14861487 try std.testing.expectError(
14871488 error.ParseZon,
14881489 fromSliceAlloc(Union, .{
14891490 .gpa = gpa,
14901491 .arena = arena,
14911492 .source = ".{.z=2.5}",
1492 .diag = &diag,
1493 .errors = &errors,
14931494 }),
14941495 );
14951496 try std.testing.expectFmt(
......@@ -1498,80 +1499,80 @@ test "std.zon unions" {
14981499 \\
14991500 ,
15001501 "{f}",
1501 .{diag},
1502 .{errors},
15021503 );
15031504 }
15041505
15051506 // Explicit void field
15061507 {
15071508 const Union = union(enum) { x: void };
1508 var diag: Diagnostics = .init(arena);
1509 var errors: Errors = .init(arena);
15091510 try std.testing.expectError(
15101511 error.ParseZon,
15111512 fromSliceAlloc(Union, .{
15121513 .gpa = gpa,
15131514 .arena = arena,
15141515 .source = ".{.x=1}",
1515 .diag = &diag,
1516 .errors = &errors,
15161517 }),
15171518 );
1518 try std.testing.expectFmt("1:6: error: expected type 'void'\n", "{f}", .{diag});
1519 try std.testing.expectFmt("1:6: error: expected type 'void'\n", "{f}", .{errors});
15191520 }
15201521
15211522 // Extra field
15221523 {
15231524 const Union = union { x: f32, y: bool };
1524 var diag: Diagnostics = .init(arena);
1525 var errors: Errors = .init(arena);
15251526 try std.testing.expectError(
15261527 error.ParseZon,
15271528 fromSliceAlloc(Union, .{
15281529 .gpa = gpa,
15291530 .arena = arena,
15301531 .source = ".{.x = 1.5, .y = true}",
1531 .diag = &diag,
1532 .errors = &errors,
15321533 }),
15331534 );
1534 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{diag});
1535 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{errors});
15351536 }
15361537
15371538 // No fields
15381539 {
15391540 const Union = union { x: f32, y: bool };
1540 var diag: Diagnostics = .init(arena);
1541 var errors: Errors = .init(arena);
15411542 try std.testing.expectError(
15421543 error.ParseZon,
15431544 fromSliceAlloc(Union, .{
15441545 .gpa = gpa,
15451546 .arena = arena,
15461547 .source = ".{}",
1547 .diag = &diag,
1548 .errors = &errors,
15481549 }),
15491550 );
1550 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{diag});
1551 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{errors});
15511552 }
15521553
15531554 // Enum literals cannot coerce into untagged unions
15541555 {
15551556 const Union = union { x: void };
1556 var diag: Diagnostics = .init(arena);
1557 var errors: Errors = .init(arena);
15571558 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{
15581559 .gpa = gpa,
15591560 .arena = arena,
15601561 .source = ".x",
1561 .diag = &diag,
1562 .errors = &errors,
15621563 }));
1563 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{diag});
1564 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{errors});
15641565 }
15651566
15661567 // Unknown field for enum literal coercion
15671568 {
15681569 const Union = union(enum) { x: void };
1569 var diag: Diagnostics = .init(arena);
1570 var errors: Errors = .init(arena);
15701571 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{
15711572 .gpa = gpa,
15721573 .arena = arena,
15731574 .source = ".y",
1574 .diag = &diag,
1575 .errors = &errors,
15751576 }));
15761577 try std.testing.expectFmt(
15771578 \\1:2: error: unexpected field 'y'
......@@ -1579,21 +1580,21 @@ test "std.zon unions" {
15791580 \\
15801581 ,
15811582 "{f}",
1582 .{diag},
1583 .{errors},
15831584 );
15841585 }
15851586
15861587 // Non void field for enum literal coercion
15871588 {
15881589 const Union = union(enum) { x: f32 };
1589 var diag: Diagnostics = .init(arena);
1590 var errors: Errors = .init(arena);
15901591 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{
15911592 .gpa = gpa,
15921593 .arena = arena,
15931594 .source = ".x",
1594 .diag = &diag,
1595 .errors = &errors,
15951596 }));
1596 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{diag});
1597 try std.testing.expectFmt("1:2: error: expected union\n", "{f}", .{errors});
15971598 }
15981599}
15991600
......@@ -1613,28 +1614,28 @@ test "std.zon structs" {
16131614 const zero = try fromSlice(Vec0, .{
16141615 .gpa = gpa,
16151616 .source = ".{}",
1616 .diag = null,
1617 .errors = null,
16171618 });
16181619 try std.testing.expectEqual(Vec0{}, zero);
16191620
16201621 const one = try fromSlice(Vec1, .{
16211622 .gpa = gpa,
16221623 .source = ".{.x = 1.2}",
1623 .diag = null,
1624 .errors = null,
16241625 });
16251626 try std.testing.expectEqual(Vec1{ .x = 1.2 }, one);
16261627
16271628 const two = try fromSlice(Vec2, .{
16281629 .gpa = gpa,
16291630 .source = ".{.x = 1.2, .y = 3.4}",
1630 .diag = null,
1631 .errors = null,
16311632 });
16321633 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 3.4 }, two);
16331634
16341635 const three = try fromSlice(Vec3, .{
16351636 .gpa = gpa,
16361637 .source = ".{.x = 1.2, .y = 3.4, .z = 5.6}",
1637 .diag = null,
1638 .errors = null,
16381639 });
16391640 try std.testing.expectEqual(Vec3{ .x = 1.2, .y = 3.4, .z = 5.6 }, three);
16401641 }
......@@ -1647,7 +1648,7 @@ test "std.zon structs" {
16471648 .gpa = gpa,
16481649 .arena = arena,
16491650 .source = ".{.bar = \"qux\", .baz = .{\"a\", \"b\"}}",
1650 .diag = null,
1651 .errors = null,
16511652 });
16521653 try std.testing.expectEqualDeep(Foo{ .bar = "qux", .baz = &.{ "a", "b" } }, parsed);
16531654 }
......@@ -1655,13 +1656,13 @@ test "std.zon structs" {
16551656 // Unknown field
16561657 {
16571658 const Vec2 = struct { x: f32, y: f32 };
1658 var diag: Diagnostics = .init(arena);
1659 var errors: Errors = .init(arena);
16591660 try std.testing.expectError(
16601661 error.ParseZon,
16611662 fromSlice(Vec2, .{
16621663 .gpa = gpa,
16631664 .source = ".{.x=1.5, .z=2.5}",
1664 .diag = &diag,
1665 .errors = &errors,
16651666 }),
16661667 );
16671668 try std.testing.expectFmt(
......@@ -1670,27 +1671,27 @@ test "std.zon structs" {
16701671 \\
16711672 ,
16721673 "{f}",
1673 .{diag},
1674 .{errors},
16741675 );
16751676 }
16761677
16771678 // Duplicate field
16781679 {
16791680 const Vec2 = struct { x: f32, y: f32 };
1680 var diag: Diagnostics = .init(arena);
1681 var errors: Errors = .init(arena);
16811682 try std.testing.expectError(
16821683 error.ParseZon,
16831684 fromSlice(Vec2, .{
16841685 .gpa = gpa,
16851686 .source = ".{.x=1.5, .x=2.5, .x=3.5}",
1686 .diag = &diag,
1687 .errors = &errors,
16871688 }),
16881689 );
16891690 try std.testing.expectFmt(
16901691 \\1:4: error: duplicate struct field name
16911692 \\1:12: note: duplicate name here
16921693 \\
1693 , "{f}", .{diag});
1694 , "{f}", .{errors});
16941695 }
16951696
16961697 // Ignore unknown fields
......@@ -1700,7 +1701,7 @@ test "std.zon structs" {
17001701 .gpa = gpa,
17011702 .source = ".{ .x = 1.0, .z = 3.0 }",
17021703 .ignore_unknown_fields = true,
1703 .diag = null,
1704 .errors = null,
17041705 });
17051706 try std.testing.expectEqual(Vec2{ .x = 1.0, .y = 2.0 }, parsed);
17061707 }
......@@ -1708,35 +1709,35 @@ test "std.zon structs" {
17081709 // Unknown field when struct has no fields (regression test)
17091710 {
17101711 const Vec2 = struct {};
1711 var diag: Diagnostics = .init(arena);
1712 var errors: Errors = .init(arena);
17121713 try std.testing.expectError(
17131714 error.ParseZon,
17141715 fromSlice(Vec2, .{
17151716 .gpa = gpa,
17161717 .source = ".{.x=1.5, .z=2.5}",
1717 .diag = &diag,
1718 .errors = &errors,
17181719 }),
17191720 );
17201721 try std.testing.expectFmt(
17211722 \\1:4: error: unexpected field 'x'
17221723 \\1:4: note: none expected
17231724 \\
1724 , "{f}", .{diag});
1725 , "{f}", .{errors});
17251726 }
17261727
17271728 // Missing field
17281729 {
17291730 const Vec2 = struct { x: f32, y: f32 };
1730 var diag: Diagnostics = .init(arena);
1731 var errors: Errors = .init(arena);
17311732 try std.testing.expectError(
17321733 error.ParseZon,
17331734 fromSlice(Vec2, .{
17341735 .gpa = gpa,
17351736 .source = ".{.x=1.5}",
1736 .diag = &diag,
1737 .errors = &errors,
17371738 }),
17381739 );
1739 try std.testing.expectFmt("1:2: error: missing required field y\n", "{f}", .{diag});
1740 try std.testing.expectFmt("1:2: error: missing required field y\n", "{f}", .{errors});
17401741 }
17411742
17421743 // Default field
......@@ -1745,7 +1746,7 @@ test "std.zon structs" {
17451746 const parsed = try fromSlice(Vec2, .{
17461747 .gpa = gpa,
17471748 .source = ".{.x = 1.2}",
1748 .diag = null,
1749 .errors = null,
17491750 });
17501751 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed);
17511752 }
......@@ -1756,7 +1757,7 @@ test "std.zon structs" {
17561757 const parsed = try fromSlice(Vec2, .{
17571758 .gpa = gpa,
17581759 .source = ".{.x = 1.2}",
1759 .diag = null,
1760 .errors = null,
17601761 });
17611762 try std.testing.expectEqual(Vec2{ .x = 1.2, .y = 1.5 }, parsed);
17621763 }
......@@ -1764,17 +1765,17 @@ test "std.zon structs" {
17641765 // Comptime field assignment
17651766 {
17661767 const Vec2 = struct { x: f32, comptime y: f32 = 1.5 };
1767 var diag: Diagnostics = .init(arena);
1768 var errors: Errors = .init(arena);
17681769 const parsed = fromSlice(Vec2, .{
17691770 .gpa = gpa,
17701771 .source = ".{.x = 1.2, .y = 1.5}",
1771 .diag = &diag,
1772 .errors = &errors,
17721773 });
17731774 try std.testing.expectError(error.ParseZon, parsed);
17741775 try std.testing.expectFmt(
17751776 \\1:18: error: cannot initialize comptime field
17761777 \\
1777 , "{f}", .{diag});
1778 , "{f}", .{errors});
17781779 }
17791780
17801781 // Enum field (regression test, we were previously getting the field name in an
......@@ -1784,7 +1785,7 @@ test "std.zon structs" {
17841785 const parsed = try fromSlice(Vec0, .{
17851786 .gpa = gpa,
17861787 .source = ".{ .x = .x }",
1787 .diag = null,
1788 .errors = null,
17881789 });
17891790 try std.testing.expectEqual(Vec0{ .x = .x }, parsed);
17901791 }
......@@ -1795,7 +1796,7 @@ test "std.zon structs" {
17951796 const parsed = try fromSlice(Vec0, .{
17961797 .gpa = gpa,
17971798 .source = ".{ .@\"x x\" = .@\"x x\" }",
1798 .diag = null,
1799 .errors = null,
17991800 });
18001801 try std.testing.expectEqual(Vec0{ .@"x x" = .@"x x" }, parsed);
18011802 }
......@@ -1804,83 +1805,83 @@ test "std.zon structs" {
18041805 {
18051806 // Structs
18061807 {
1807 var diag: Diagnostics = .init(arena);
1808 var errors: Errors = .init(arena);
18081809 const parsed = fromSlice(struct {}, .{
18091810 .gpa = gpa,
18101811 .source = "Empty{}",
1811 .diag = &diag,
1812 .errors = &errors,
18121813 });
18131814 try std.testing.expectError(error.ParseZon, parsed);
18141815 try std.testing.expectFmt(
18151816 \\1:1: error: types are not available in ZON
18161817 \\1:1: note: replace the type with '.'
18171818 \\
1818 , "{f}", .{diag});
1819 , "{f}", .{errors});
18191820 }
18201821
18211822 // Arrays
18221823 {
1823 var diag: Diagnostics = .init(arena);
1824 var errors: Errors = .init(arena);
18241825 const parsed = fromSlice([3]u8, .{
18251826 .gpa = gpa,
18261827 .source = "[3]u8{1, 2, 3}",
1827 .diag = &diag,
1828 .errors = &errors,
18281829 });
18291830 try std.testing.expectError(error.ParseZon, parsed);
18301831 try std.testing.expectFmt(
18311832 \\1:1: error: types are not available in ZON
18321833 \\1:1: note: replace the type with '.'
18331834 \\
1834 , "{f}", .{diag});
1835 , "{f}", .{errors});
18351836 }
18361837
18371838 // Slices
18381839 {
1839 var diag: Diagnostics = .init(arena);
1840 var errors: Errors = .init(arena);
18401841 const parsed = fromSliceAlloc([]u8, .{
18411842 .gpa = gpa,
18421843 .arena = arena,
18431844 .source = "[]u8{1, 2, 3}",
1844 .diag = &diag,
1845 .errors = &errors,
18451846 });
18461847 try std.testing.expectError(error.ParseZon, parsed);
18471848 try std.testing.expectFmt(
18481849 \\1:1: error: types are not available in ZON
18491850 \\1:1: note: replace the type with '.'
18501851 \\
1851 , "{f}", .{diag});
1852 , "{f}", .{errors});
18521853 }
18531854
18541855 // Tuples
18551856 {
1856 var diag: Diagnostics = .init(arena);
1857 var errors: Errors = .init(arena);
18571858 const parsed = fromSlice(struct { u8, u8, u8 }, .{
18581859 .gpa = gpa,
18591860 .source = "Tuple{1, 2, 3}",
1860 .diag = &diag,
1861 .errors = &errors,
18611862 });
18621863 try std.testing.expectError(error.ParseZon, parsed);
18631864 try std.testing.expectFmt(
18641865 \\1:1: error: types are not available in ZON
18651866 \\1:1: note: replace the type with '.'
18661867 \\
1867 , "{f}", .{diag});
1868 , "{f}", .{errors});
18681869 }
18691870
18701871 // Nested
18711872 {
1872 var diag: Diagnostics = .init(arena);
1873 var errors: Errors = .init(arena);
18731874 const parsed = fromSlice(struct {}, .{
18741875 .gpa = gpa,
18751876 .source = ".{ .x = Tuple{1, 2, 3} }",
1876 .diag = &diag,
1877 .errors = &errors,
18771878 });
18781879 try std.testing.expectError(error.ParseZon, parsed);
18791880 try std.testing.expectFmt(
18801881 \\1:9: error: types are not available in ZON
18811882 \\1:9: note: replace the type with '.'
18821883 \\
1883 , "{f}", .{diag});
1884 , "{f}", .{errors});
18841885 }
18851886 }
18861887}
......@@ -1901,28 +1902,28 @@ test "std.zon tuples" {
19011902 const zero = try fromSlice(Tuple0, .{
19021903 .gpa = gpa,
19031904 .source = ".{}",
1904 .diag = null,
1905 .errors = null,
19051906 });
19061907 try std.testing.expectEqual(Tuple0{}, zero);
19071908
19081909 const one = try fromSlice(Tuple1, .{
19091910 .gpa = gpa,
19101911 .source = ".{1.2}",
1911 .diag = null,
1912 .errors = null,
19121913 });
19131914 try std.testing.expectEqual(Tuple1{1.2}, one);
19141915
19151916 const two = try fromSlice(Tuple2, .{
19161917 .gpa = gpa,
19171918 .source = ".{1.2, true}",
1918 .diag = null,
1919 .errors = null,
19191920 });
19201921 try std.testing.expectEqual(Tuple2{ 1.2, true }, two);
19211922
19221923 const three = try fromSlice(Tuple3, .{
19231924 .gpa = gpa,
19241925 .source = ".{1.2, false, 3}",
1925 .diag = null,
1926 .errors = null,
19261927 });
19271928 try std.testing.expectEqual(Tuple3{ 1.2, false, 3 }, three);
19281929 }
......@@ -1934,7 +1935,7 @@ test "std.zon tuples" {
19341935 .gpa = gpa,
19351936 .arena = arena,
19361937 .source = ".{\"hello\", \"world\"}",
1937 .diag = null,
1938 .errors = null,
19381939 });
19391940 try std.testing.expectEqualDeep(Tuple{ "hello", "world" }, parsed);
19401941 }
......@@ -1942,65 +1943,65 @@ test "std.zon tuples" {
19421943 // Extra field
19431944 {
19441945 const Tuple = struct { f32, bool };
1945 var diag: Diagnostics = .init(arena);
1946 var errors: Errors = .init(arena);
19461947 try std.testing.expectError(
19471948 error.ParseZon,
19481949 fromSlice(Tuple, .{
19491950 .gpa = gpa,
19501951 .source = ".{0.5, true, 123}",
1951 .diag = &diag,
1952 .errors = &errors,
19521953 }),
19531954 );
1954 try std.testing.expectFmt("1:14: error: index 2 outside of tuple length 2\n", "{f}", .{diag});
1955 try std.testing.expectFmt("1:14: error: index 2 outside of tuple length 2\n", "{f}", .{errors});
19551956 }
19561957
19571958 // Extra field
19581959 {
19591960 const Tuple = struct { f32, bool };
1960 var diag: Diagnostics = .init(arena);
1961 var errors: Errors = .init(arena);
19611962 try std.testing.expectError(
19621963 error.ParseZon,
19631964 fromSlice(Tuple, .{
19641965 .gpa = gpa,
19651966 .source = ".{0.5}",
1966 .diag = &diag,
1967 .errors = &errors,
19671968 }),
19681969 );
19691970 try std.testing.expectFmt(
19701971 "1:2: error: missing tuple field with index 1\n",
19711972 "{f}",
1972 .{diag},
1973 .{errors},
19731974 );
19741975 }
19751976
19761977 // Tuple with unexpected field names
19771978 {
19781979 const Tuple = struct { f32 };
1979 var diag: Diagnostics = .init(arena);
1980 var errors: Errors = .init(arena);
19801981 try std.testing.expectError(
19811982 error.ParseZon,
19821983 fromSlice(Tuple, .{
19831984 .gpa = gpa,
19841985 .source = ".{.foo = 10.0}",
1985 .diag = &diag,
1986 .errors = &errors,
19861987 }),
19871988 );
1988 try std.testing.expectFmt("1:2: error: expected tuple\n", "{f}", .{diag});
1989 try std.testing.expectFmt("1:2: error: expected tuple\n", "{f}", .{errors});
19891990 }
19901991
19911992 // Struct with missing field names
19921993 {
19931994 const Struct = struct { foo: f32 };
1994 var diag: Diagnostics = .init(arena);
1995 var errors: Errors = .init(arena);
19951996 try std.testing.expectError(
19961997 error.ParseZon,
19971998 fromSlice(Struct, .{
19981999 .gpa = gpa,
19992000 .source = ".{10.0}",
2000 .diag = &diag,
2001 .errors = &errors,
20012002 }),
20022003 );
2003 try std.testing.expectFmt("1:2: error: expected struct\n", "{f}", .{diag});
2004 try std.testing.expectFmt("1:2: error: expected struct\n", "{f}", .{errors});
20042005 }
20052006
20062007 // Comptime field
......@@ -2009,7 +2010,7 @@ test "std.zon tuples" {
20092010 const parsed = try fromSlice(Vec2, .{
20102011 .gpa = gpa,
20112012 .source = ".{ 1.2 }",
2012 .diag = null,
2013 .errors = null,
20132014 });
20142015 try std.testing.expectEqual(Vec2{ 1.2, 1.5 }, parsed);
20152016 }
......@@ -2017,17 +2018,17 @@ test "std.zon tuples" {
20172018 // Comptime field assignment
20182019 {
20192020 const Vec2 = struct { f32, comptime f32 = 1.5 };
2020 var diag: Diagnostics = .init(arena);
2021 var errors: Errors = .init(arena);
20212022 const parsed = fromSlice(Vec2, .{
20222023 .gpa = gpa,
20232024 .source = ".{ 1.2, 1.5}",
2024 .diag = &diag,
2025 .errors = &errors,
20252026 });
20262027 try std.testing.expectError(error.ParseZon, parsed);
20272028 try std.testing.expectFmt(
20282029 \\1:9: error: cannot initialize comptime field
20292030 \\
2030 , "{f}", .{diag});
2031 , "{f}", .{errors});
20312032 }
20322033}
20332034
......@@ -2045,42 +2046,42 @@ test "std.zon arrays and slices" {
20452046 const zero = try fromSlice([0]u8, .{
20462047 .gpa = gpa,
20472048 .source = ".{}",
2048 .diag = null,
2049 .errors = null,
20492050 });
20502051 try std.testing.expectEqualSlices(u8, &@as([0]u8, .{}), &zero);
20512052
20522053 const one = try fromSlice([1]u8, .{
20532054 .gpa = gpa,
20542055 .source = ".{'a'}",
2055 .diag = null,
2056 .errors = null,
20562057 });
20572058 try std.testing.expectEqualSlices(u8, &@as([1]u8, .{'a'}), &one);
20582059
20592060 const two = try fromSlice([2]u8, .{
20602061 .gpa = gpa,
20612062 .source = ".{'a', 'b'}",
2062 .diag = null,
2063 .errors = null,
20632064 });
20642065 try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two);
20652066
20662067 const two_comma = try fromSlice([2]u8, .{
20672068 .gpa = gpa,
20682069 .source = ".{'a', 'b',}",
2069 .diag = null,
2070 .errors = null,
20702071 });
20712072 try std.testing.expectEqualSlices(u8, &@as([2]u8, .{ 'a', 'b' }), &two_comma);
20722073
20732074 const three = try fromSlice([3]u8, .{
20742075 .gpa = gpa,
20752076 .source = ".{'a', 'b', 'c'}",
2076 .diag = null,
2077 .errors = null,
20772078 });
20782079 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, &three);
20792080
20802081 const sentinel = try fromSlice([3:'z']u8, .{
20812082 .gpa = gpa,
20822083 .source = ".{'a', 'b', 'c'}",
2083 .diag = null,
2084 .errors = null,
20842085 });
20852086 const expected_sentinel: [3:'z']u8 = .{ 'a', 'b', 'c' };
20862087 try std.testing.expectEqualSlices(u8, &expected_sentinel, &sentinel);
......@@ -2092,7 +2093,7 @@ test "std.zon arrays and slices" {
20922093 .gpa = gpa,
20932094 .arena = arena,
20942095 .source = ".{}",
2095 .diag = null,
2096 .errors = null,
20962097 });
20972098 try std.testing.expectEqualSlices(u8, @as([]const u8, &.{}), zero);
20982099
......@@ -2100,7 +2101,7 @@ test "std.zon arrays and slices" {
21002101 .gpa = gpa,
21012102 .arena = arena,
21022103 .source = ".{'a'}",
2103 .diag = null,
2104 .errors = null,
21042105 });
21052106 try std.testing.expectEqualSlices(u8, &.{'a'}, one);
21062107
......@@ -2108,7 +2109,7 @@ test "std.zon arrays and slices" {
21082109 .gpa = gpa,
21092110 .arena = arena,
21102111 .source = ".{'a', 'b'}",
2111 .diag = null,
2112 .errors = null,
21122113 });
21132114 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two);
21142115
......@@ -2116,7 +2117,7 @@ test "std.zon arrays and slices" {
21162117 .gpa = gpa,
21172118 .arena = arena,
21182119 .source = ".{'a', 'b',}",
2119 .diag = null,
2120 .errors = null,
21202121 });
21212122 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b' }, two_comma);
21222123
......@@ -2124,7 +2125,7 @@ test "std.zon arrays and slices" {
21242125 .gpa = gpa,
21252126 .arena = arena,
21262127 .source = ".{'a', 'b', 'c'}",
2127 .diag = null,
2128 .errors = null,
21282129 });
21292130 try std.testing.expectEqualSlices(u8, &.{ 'a', 'b', 'c' }, three);
21302131
......@@ -2132,7 +2133,7 @@ test "std.zon arrays and slices" {
21322133 .gpa = gpa,
21332134 .arena = arena,
21342135 .source = ".{'a', 'b', 'c'}",
2135 .diag = null,
2136 .errors = null,
21362137 });
21372138 const expected_sentinel: [:'z']const u8 = &.{ 'a', 'b', 'c' };
21382139 try std.testing.expectEqualSlices(u8, expected_sentinel, sentinel);
......@@ -2147,7 +2148,7 @@ test "std.zon arrays and slices" {
21472148 .gpa = gpa,
21482149 .arena = arena,
21492150 .source = ".{\"abc\"}",
2150 .diag = null,
2151 .errors = null,
21512152 });
21522153 const expected: [1][]const u8 = .{"abc"};
21532154 try std.testing.expectEqualDeep(expected, parsed);
......@@ -2159,7 +2160,7 @@ test "std.zon arrays and slices" {
21592160 .gpa = gpa,
21602161 .arena = arena,
21612162 .source = ".{\"abc\"}",
2162 .diag = null,
2163 .errors = null,
21632164 });
21642165 const expected: []const []const u8 = &.{"abc"};
21652166 try std.testing.expectEqualDeep(expected, parsed);
......@@ -2173,7 +2174,7 @@ test "std.zon arrays and slices" {
21732174 const sentinel = try fromSlice([1:2]u8, .{
21742175 .gpa = gpa,
21752176 .source = ".{1}",
2176 .diag = null,
2177 .errors = null,
21772178 });
21782179 try std.testing.expectEqual(@as(usize, 1), sentinel.len);
21792180 try std.testing.expectEqual(@as(u8, 1), sentinel[0]);
......@@ -2186,7 +2187,7 @@ test "std.zon arrays and slices" {
21862187 .gpa = gpa,
21872188 .arena = arena,
21882189 .source = ".{1}",
2189 .diag = null,
2190 .errors = null,
21902191 });
21912192 try std.testing.expectEqual(@as(usize, 1), sentinel.len);
21922193 try std.testing.expectEqual(@as(u8, 1), sentinel[0]);
......@@ -2196,73 +2197,73 @@ test "std.zon arrays and slices" {
21962197
21972198 // Expect 0 find 3
21982199 {
2199 var diag: Diagnostics = .init(arena);
2200 var errors: Errors = .init(arena);
22002201 try std.testing.expectError(
22012202 error.ParseZon,
22022203 fromSlice([0]u8, .{
22032204 .gpa = gpa,
22042205 .source = ".{'a', 'b', 'c'}",
2205 .diag = &diag,
2206 .errors = &errors,
22062207 }),
22072208 );
22082209 try std.testing.expectFmt(
22092210 "1:3: error: index 0 outside of array of length 0\n",
22102211 "{f}",
2211 .{diag},
2212 .{errors},
22122213 );
22132214 }
22142215
22152216 // Expect 1 find 2
22162217 {
2217 var diag: Diagnostics = .init(arena);
2218 var errors: Errors = .init(arena);
22182219 try std.testing.expectError(
22192220 error.ParseZon,
22202221 fromSlice([1]u8, .{
22212222 .gpa = gpa,
22222223 .source = ".{'a', 'b'}",
2223 .diag = &diag,
2224 .errors = &errors,
22242225 }),
22252226 );
22262227 try std.testing.expectFmt(
22272228 "1:8: error: index 1 outside of array of length 1\n",
22282229 "{f}",
2229 .{diag},
2230 .{errors},
22302231 );
22312232 }
22322233
22332234 // Expect 2 find 1
22342235 {
2235 var diag: Diagnostics = .init(arena);
2236 var errors: Errors = .init(arena);
22362237 try std.testing.expectError(
22372238 error.ParseZon,
22382239 fromSlice([2]u8, .{
22392240 .gpa = gpa,
22402241 .source = ".{'a'}",
2241 .diag = &diag,
2242 .errors = &errors,
22422243 }),
22432244 );
22442245 try std.testing.expectFmt(
22452246 "1:2: error: expected 2 array elements; found 1\n",
22462247 "{f}",
2247 .{diag},
2248 .{errors},
22482249 );
22492250 }
22502251
22512252 // Expect 3 find 0
22522253 {
2253 var diag: Diagnostics = .init(arena);
2254 var errors: Errors = .init(arena);
22542255 try std.testing.expectError(
22552256 error.ParseZon,
22562257 fromSlice([3]u8, .{
22572258 .gpa = gpa,
22582259 .source = ".{}",
2259 .diag = &diag,
2260 .errors = &errors,
22602261 }),
22612262 );
22622263 try std.testing.expectFmt(
22632264 "1:2: error: expected 3 array elements; found 0\n",
22642265 "{f}",
2265 .{diag},
2266 .{errors},
22662267 );
22672268 }
22682269
......@@ -2270,31 +2271,31 @@ test "std.zon arrays and slices" {
22702271 {
22712272 // Array
22722273 {
2273 var diag: Diagnostics = .init(arena);
2274 var errors: Errors = .init(arena);
22742275 try std.testing.expectError(
22752276 error.ParseZon,
22762277 fromSlice([3]bool, .{
22772278 .gpa = gpa,
22782279 .source = ".{'a', 'b', 'c'}",
2279 .diag = &diag,
2280 .errors = &errors,
22802281 }),
22812282 );
2282 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{f}", .{diag});
2283 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{f}", .{errors});
22832284 }
22842285
22852286 // Slice
22862287 {
2287 var diag: Diagnostics = .init(arena);
2288 var errors: Errors = .init(arena);
22882289 try std.testing.expectError(
22892290 error.ParseZon,
22902291 fromSliceAlloc([]bool, .{
22912292 .gpa = gpa,
22922293 .arena = arena,
22932294 .source = ".{'a', 'b', 'c'}",
2294 .diag = &diag,
2295 .errors = &errors,
22952296 }),
22962297 );
2297 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{f}", .{diag});
2298 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{f}", .{errors});
22982299 }
22992300 }
23002301
......@@ -2302,40 +2303,40 @@ test "std.zon arrays and slices" {
23022303 {
23032304 // Array
23042305 {
2305 var diag: Diagnostics = .init(arena);
2306 var errors: Errors = .init(arena);
23062307 try std.testing.expectError(
23072308 error.ParseZon,
23082309 fromSlice([3]u8, .{
23092310 .gpa = gpa,
23102311 .source = "'a'",
2311 .diag = &diag,
2312 .errors = &errors,
23122313 }),
23132314 );
2314 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2315 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
23152316 }
23162317
23172318 // Slice
23182319 {
2319 var diag: Diagnostics = .init(arena);
2320 var errors: Errors = .init(arena);
23202321 try std.testing.expectError(
23212322 error.ParseZon,
2322 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "'a'", .diag = &diag }),
2323 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "'a'", .errors = &errors }),
23232324 );
2324 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2325 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
23252326 }
23262327 }
23272328
23282329 // Address of is not allowed (indirection for slices in ZON is implicit)
23292330 {
2330 var diag: Diagnostics = .init(arena);
2331 var errors: Errors = .init(arena);
23312332 try std.testing.expectError(
23322333 error.ParseZon,
2333 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = " &.{'a', 'b', 'c'}", .diag = &diag }),
2334 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = " &.{'a', 'b', 'c'}", .errors = &errors }),
23342335 );
23352336 try std.testing.expectFmt(
23362337 "1:3: error: pointers are not available in ZON\n",
23372338 "{f}",
2338 .{diag},
2339 .{errors},
23392340 );
23402341 }
23412342}
......@@ -2352,7 +2353,7 @@ test "std.zon string literal" {
23522353 .gpa = gpa,
23532354 .arena = arena,
23542355 .source = "\"abc\"",
2355 .diag = null,
2356 .errors = null,
23562357 });
23572358 try std.testing.expectEqualStrings(@as([]const u8, "abc"), parsed);
23582359 }
......@@ -2363,7 +2364,7 @@ test "std.zon string literal" {
23632364 .gpa = gpa,
23642365 .arena = arena,
23652366 .source = "\"ab\\nc\"",
2366 .diag = null,
2367 .errors = null,
23672368 });
23682369 try std.testing.expectEqualStrings(@as([]const u8, "ab\nc"), parsed);
23692370 }
......@@ -2374,7 +2375,7 @@ test "std.zon string literal" {
23742375 .gpa = gpa,
23752376 .arena = arena,
23762377 .source = "\"ab\\x00c\"",
2377 .diag = null,
2378 .errors = null,
23782379 });
23792380 try std.testing.expectEqualStrings(@as([]const u8, "ab\x00c"), parsed);
23802381 }
......@@ -2382,21 +2383,21 @@ test "std.zon string literal" {
23822383 // Passing string literal to a mutable slice
23832384 {
23842385 {
2385 var diag: Diagnostics = .init(arena);
2386 var errors: Errors = .init(arena);
23862387 try std.testing.expectError(
23872388 error.ParseZon,
2388 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "\"abcd\"", .diag = &diag }),
2389 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "\"abcd\"", .errors = &errors }),
23892390 );
2390 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2391 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
23912392 }
23922393
23932394 {
2394 var diag: Diagnostics = .init(arena);
2395 var errors: Errors = .init(arena);
23952396 try std.testing.expectError(
23962397 error.ParseZon,
2397 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\abcd", .diag = &diag }),
2398 fromSliceAlloc([]u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\abcd", .errors = &errors }),
23982399 );
2399 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2400 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
24002401 }
24012402 }
24022403
......@@ -2407,29 +2408,29 @@ test "std.zon string literal" {
24072408 defer ast.deinit(gpa);
24082409 var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false });
24092410 defer zoir.deinit(gpa);
2410 var diag: Diagnostics = .init(arena);
2411 var errors: Errors = .init(arena);
24112412 try std.testing.expectError(
24122413 error.ParseZon,
24132414 fromSlice([4:0]u8, .{
24142415 .gpa = gpa,
24152416 .source = "\"abcd\"",
2416 .diag = &diag,
2417 .errors = &errors,
24172418 }),
24182419 );
2419 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2420 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
24202421 }
24212422
24222423 {
2423 var diag: Diagnostics = .init(arena);
2424 var errors: Errors = .init(arena);
24242425 try std.testing.expectError(
24252426 error.ParseZon,
24262427 fromSlice([4:0]u8, .{
24272428 .gpa = gpa,
24282429 .source = "\\\\abcd",
2429 .diag = &diag,
2430 .errors = &errors,
24302431 }),
24312432 );
2432 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2433 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
24332434 }
24342435 }
24352436
......@@ -2440,7 +2441,7 @@ test "std.zon string literal" {
24402441 .gpa = gpa,
24412442 .arena = arena,
24422443 .source = "\"abc\"",
2443 .diag = null,
2444 .errors = null,
24442445 });
24452446 try std.testing.expectEqualStrings("abc", parsed);
24462447 try std.testing.expectEqual(@as(u8, 0), parsed[3]);
......@@ -2451,7 +2452,7 @@ test "std.zon string literal" {
24512452 .gpa = gpa,
24522453 .arena = arena,
24532454 .source = "\\\\abc",
2454 .diag = null,
2455 .errors = null,
24552456 });
24562457 try std.testing.expectEqualStrings("abc", parsed);
24572458 try std.testing.expectEqual(@as(u8, 0), parsed[3]);
......@@ -2461,103 +2462,103 @@ test "std.zon string literal" {
24612462 // Other value terminated slices
24622463 {
24632464 {
2464 var diag: Diagnostics = .init(arena);
2465 var errors: Errors = .init(arena);
24652466 try std.testing.expectError(
24662467 error.ParseZon,
2467 fromSliceAlloc([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\"foo\"", .diag = &diag }),
2468 fromSliceAlloc([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\"foo\"", .errors = &errors }),
24682469 );
2469 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2470 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
24702471 }
24712472
24722473 {
2473 var diag: Diagnostics = .init(arena);
2474 var errors: Errors = .init(arena);
24742475 try std.testing.expectError(
24752476 error.ParseZon,
2476 fromSliceAlloc([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\foo", .diag = &diag }),
2477 fromSliceAlloc([:1]const u8, .{ .gpa = gpa, .arena = arena, .source = "\\\\foo", .errors = &errors }),
24772478 );
2478 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2479 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
24792480 }
24802481 }
24812482
24822483 // Expecting string literal, getting something else
24832484 {
2484 var diag: Diagnostics = .init(arena);
2485 var errors: Errors = .init(arena);
24852486 try std.testing.expectError(
24862487 error.ParseZon,
2487 fromSliceAlloc([]const u8, .{ .gpa = gpa, .arena = arena, .source = "true", .diag = &diag }),
2488 fromSliceAlloc([]const u8, .{ .gpa = gpa, .arena = arena, .source = "true", .errors = &errors }),
24882489 );
2489 try std.testing.expectFmt("1:1: error: expected string\n", "{f}", .{diag});
2490 try std.testing.expectFmt("1:1: error: expected string\n", "{f}", .{errors});
24902491 }
24912492
24922493 // Expecting string literal, getting an incompatible tuple
24932494 {
2494 var diag: Diagnostics = .init(arena);
2495 var errors: Errors = .init(arena);
24952496 try std.testing.expectError(
24962497 error.ParseZon,
2497 fromSliceAlloc([]const u8, .{ .gpa = gpa, .arena = arena, .source = ".{false}", .diag = &diag }),
2498 fromSliceAlloc([]const u8, .{ .gpa = gpa, .arena = arena, .source = ".{false}", .errors = &errors }),
24982499 );
2499 try std.testing.expectFmt("1:3: error: expected type 'u8'\n", "{f}", .{diag});
2500 try std.testing.expectFmt("1:3: error: expected type 'u8'\n", "{f}", .{errors});
25002501 }
25012502
25022503 // Invalid string literal
25032504 {
2504 var diag: Diagnostics = .init(arena);
2505 var errors: Errors = .init(arena);
25052506 try std.testing.expectError(
25062507 error.ParseZon,
2507 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"\\a\"", .diag = &diag }),
2508 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"\\a\"", .errors = &errors }),
25082509 );
2509 try std.testing.expectFmt("1:3: error: invalid escape character: 'a'\n", "{f}", .{diag});
2510 try std.testing.expectFmt("1:3: error: invalid escape character: 'a'\n", "{f}", .{errors});
25102511 }
25112512
25122513 // Slice wrong child type
25132514 {
25142515 {
2515 var diag: Diagnostics = .init(arena);
2516 var errors: Errors = .init(arena);
25162517 try std.testing.expectError(
25172518 error.ParseZon,
2518 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"a\"", .diag = &diag }),
2519 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\"a\"", .errors = &errors }),
25192520 );
2520 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2521 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
25212522 }
25222523
25232524 {
2524 var diag: Diagnostics = .init(arena);
2525 var errors: Errors = .init(arena);
25252526 try std.testing.expectError(
25262527 error.ParseZon,
2527 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\\\\a", .diag = &diag }),
2528 fromSliceAlloc([]const i8, .{ .gpa = gpa, .arena = arena, .source = "\\\\a", .errors = &errors }),
25282529 );
2529 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2530 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
25302531 }
25312532 }
25322533
25332534 // Bad alignment
25342535 {
25352536 {
2536 var diag: Diagnostics = .init(arena);
2537 var errors: Errors = .init(arena);
25372538 try std.testing.expectError(
25382539 error.ParseZon,
25392540 fromSliceAlloc([]align(2) const u8, .{
25402541 .gpa = gpa,
25412542 .arena = arena,
25422543 .source = "\"abc\"",
2543 .diag = &diag,
2544 .errors = &errors,
25442545 }),
25452546 );
2546 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2547 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
25472548 }
25482549
25492550 {
2550 var diag: Diagnostics = .init(arena);
2551 var errors: Errors = .init(arena);
25512552 try std.testing.expectError(
25522553 error.ParseZon,
25532554 fromSliceAlloc([]align(2) const u8, .{
25542555 .gpa = gpa,
25552556 .arena = arena,
25562557 .source = "\\\\abc",
2557 .diag = &diag,
2558 .errors = &errors,
25582559 }),
25592560 );
2560 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{diag});
2561 try std.testing.expectFmt("1:1: error: expected array\n", "{f}", .{errors});
25612562 }
25622563 }
25632564
......@@ -2591,7 +2592,7 @@ test "std.zon string literal" {
25912592 \\ \\and this.
25922593 \\}
25932594 ,
2594 .diag = null,
2595 .errors = null,
25952596 });
25962597 try std.testing.expectEqualStrings(
25972598 "hello, world!\nthis is a multiline string!\n\n...",
......@@ -2620,36 +2621,36 @@ test "std.zon enum literals" {
26202621 try std.testing.expectEqual(Enum.foo, try fromSlice(Enum, .{
26212622 .gpa = gpa,
26222623 .source = ".foo",
2623 .diag = null,
2624 .errors = null,
26242625 }));
26252626 try std.testing.expectEqual(Enum.bar, try fromSlice(Enum, .{
26262627 .gpa = gpa,
26272628 .source = ".bar",
2628 .diag = null,
2629 .errors = null,
26292630 }));
26302631 try std.testing.expectEqual(Enum.baz, try fromSlice(Enum, .{
26312632 .gpa = gpa,
26322633 .source = ".baz",
2633 .diag = null,
2634 .errors = null,
26342635 }));
26352636 try std.testing.expectEqual(
26362637 Enum.@"ab\nc",
26372638 try fromSlice(Enum, .{
26382639 .gpa = gpa,
26392640 .source = ".@\"ab\\nc\"",
2640 .diag = null,
2641 .errors = null,
26412642 }),
26422643 );
26432644
26442645 // Bad tag
26452646 {
2646 var diag: Diagnostics = .init(arena);
2647 var errors: Errors = .init(arena);
26472648 try std.testing.expectError(
26482649 error.ParseZon,
26492650 fromSlice(Enum, .{
26502651 .gpa = gpa,
26512652 .source = ".qux",
2652 .diag = &diag,
2653 .errors = &errors,
26532654 }),
26542655 );
26552656 try std.testing.expectFmt(
......@@ -2658,19 +2659,19 @@ test "std.zon enum literals" {
26582659 \\
26592660 ,
26602661 "{f}",
2661 .{diag},
2662 .{errors},
26622663 );
26632664 }
26642665
26652666 // Bad tag that's too long for parser
26662667 {
2667 var diag: Diagnostics = .init(arena);
2668 var errors: Errors = .init(arena);
26682669 try std.testing.expectError(
26692670 error.ParseZon,
26702671 fromSlice(Enum, .{
26712672 .gpa = gpa,
26722673 .source = ".@\"foobarbaz\"",
2673 .diag = &diag,
2674 .errors = &errors,
26742675 }),
26752676 );
26762677 try std.testing.expectFmt(
......@@ -2679,39 +2680,39 @@ test "std.zon enum literals" {
26792680 \\
26802681 ,
26812682 "{f}",
2682 .{diag},
2683 .{errors},
26832684 );
26842685 }
26852686
26862687 // Bad type
26872688 {
2688 var diag: Diagnostics = .init(arena);
2689 var errors: Errors = .init(arena);
26892690 try std.testing.expectError(
26902691 error.ParseZon,
26912692 fromSlice(Enum, .{
26922693 .gpa = gpa,
26932694 .source = "true",
2694 .diag = &diag,
2695 .errors = &errors,
26952696 }),
26962697 );
2697 try std.testing.expectFmt("1:1: error: expected enum literal\n", "{f}", .{diag});
2698 try std.testing.expectFmt("1:1: error: expected enum literal\n", "{f}", .{errors});
26982699 }
26992700
27002701 // Test embedded nulls in an identifier
27012702 {
2702 var diag: Diagnostics = .init(arena);
2703 var errors: Errors = .init(arena);
27032704 try std.testing.expectError(
27042705 error.ParseZon,
27052706 fromSlice(Enum, .{
27062707 .gpa = gpa,
27072708 .source = ".@\"\\x00\"",
2708 .diag = &diag,
2709 .errors = &errors,
27092710 }),
27102711 );
27112712 try std.testing.expectFmt(
27122713 "1:2: error: identifier cannot contain null bytes\n",
27132714 "{f}",
2714 .{diag},
2715 .{errors},
27152716 );
27162717 }
27172718}
......@@ -2726,23 +2727,23 @@ test "std.zon parse bool" {
27262727 try std.testing.expectEqual(true, try fromSlice(bool, .{
27272728 .gpa = gpa,
27282729 .source = "true",
2729 .diag = null,
2730 .errors = null,
27302731 }));
27312732 try std.testing.expectEqual(false, try fromSlice(bool, .{
27322733 .gpa = gpa,
27332734 .source = "false",
2734 .diag = null,
2735 .errors = null,
27352736 }));
27362737
27372738 // Errors
27382739 {
2739 var diag: Diagnostics = .init(arena);
2740 var errors: Errors = .init(arena);
27402741 try std.testing.expectError(
27412742 error.ParseZon,
27422743 fromSlice(bool, .{
27432744 .gpa = gpa,
27442745 .source = " foo",
2745 .diag = &diag,
2746 .errors = &errors,
27462747 }),
27472748 );
27482749 try std.testing.expectFmt(
......@@ -2750,16 +2751,16 @@ test "std.zon parse bool" {
27502751 \\1:2: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
27512752 \\1:2: note: precede identifier with '.' for an enum literal
27522753 \\
2753 , "{f}", .{diag});
2754 , "{f}", .{errors});
27542755 }
27552756 {
2756 var diag: Diagnostics = .init(arena);
2757 var errors: Errors = .init(arena);
27572758 try std.testing.expectError(error.ParseZon, fromSlice(bool, .{
27582759 .gpa = gpa,
27592760 .source = "123",
2760 .diag = &diag,
2761 .errors = &errors,
27612762 }));
2762 try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{f}", .{diag});
2763 try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{f}", .{errors});
27632764 }
27642765}
27652766
......@@ -2795,46 +2796,46 @@ test "std.zon parse int" {
27952796 try std.testing.expectEqual(@as(u8, 10), try fromSlice(u8, .{
27962797 .gpa = gpa,
27972798 .source = "10",
2798 .diag = null,
2799 .errors = null,
27992800 }));
28002801 try std.testing.expectEqual(@as(i16, 24), try fromSlice(i16, .{
28012802 .gpa = gpa,
28022803 .source = "24",
2803 .diag = null,
2804 .errors = null,
28042805 }));
28052806 try std.testing.expectEqual(@as(i14, -4), try fromSlice(i14, .{
28062807 .gpa = gpa,
28072808 .source = "-4",
2808 .diag = null,
2809 .errors = null,
28092810 }));
28102811 try std.testing.expectEqual(@as(i32, -123), try fromSlice(i32, .{
28112812 .gpa = gpa,
28122813 .source = "-123",
2813 .diag = null,
2814 .errors = null,
28142815 }));
28152816
28162817 // Test limits
28172818 try std.testing.expectEqual(@as(i8, 127), try fromSlice(i8, .{
28182819 .gpa = gpa,
28192820 .source = "127",
2820 .diag = null,
2821 .errors = null,
28212822 }));
28222823 try std.testing.expectEqual(@as(i8, -128), try fromSlice(i8, .{
28232824 .gpa = gpa,
28242825 .source = "-128",
2825 .diag = null,
2826 .errors = null,
28262827 }));
28272828
28282829 // Test characters
28292830 try std.testing.expectEqual(@as(u8, 'a'), try fromSlice(u8, .{
28302831 .gpa = gpa,
28312832 .source = "'a'",
2832 .diag = null,
2833 .errors = null,
28332834 }));
28342835 try std.testing.expectEqual(@as(u8, 'z'), try fromSlice(u8, .{
28352836 .gpa = gpa,
28362837 .source = "'z'",
2837 .diag = null,
2838 .errors = null,
28382839 }));
28392840
28402841 // Test big integers
......@@ -2843,7 +2844,7 @@ test "std.zon parse int" {
28432844 try fromSlice(u65, .{
28442845 .gpa = gpa,
28452846 .source = "36893488147419103231",
2846 .diag = null,
2847 .errors = null,
28472848 }),
28482849 );
28492850 try std.testing.expectEqual(
......@@ -2851,7 +2852,7 @@ test "std.zon parse int" {
28512852 try fromSlice(u65, .{
28522853 .gpa = gpa,
28532854 .source = "368934_881_474191032_31",
2854 .diag = null,
2855 .errors = null,
28552856 }),
28562857 );
28572858 try std.testing.expectEqual(
......@@ -2859,7 +2860,7 @@ test "std.zon parse int" {
28592860 try fromSlice(u128, .{
28602861 .gpa = gpa,
28612862 .source = "340282366920938463463374607431768211455",
2862 .diag = null,
2863 .errors = null,
28632864 }),
28642865 );
28652866
......@@ -2869,7 +2870,7 @@ test "std.zon parse int" {
28692870 try fromSlice(i66, .{
28702871 .gpa = gpa,
28712872 .source = "36893488147419103231",
2872 .diag = null,
2873 .errors = null,
28732874 }),
28742875 );
28752876 try std.testing.expectEqual(
......@@ -2877,33 +2878,33 @@ test "std.zon parse int" {
28772878 try fromSlice(i66, .{
28782879 .gpa = gpa,
28792880 .source = "-36893488147419103232",
2880 .diag = null,
2881 .errors = null,
28812882 }),
28822883 );
28832884 {
2884 var diag: Diagnostics = .init(arena);
2885 var errors: Errors = .init(arena);
28852886 try std.testing.expectError(error.ParseZon, fromSlice(i66, .{
28862887 .gpa = gpa,
28872888 .source = "36893488147419103232",
2888 .diag = &diag,
2889 .errors = &errors,
28892890 }));
28902891 try std.testing.expectFmt(
28912892 "1:1: error: type 'i66' cannot represent value\n",
28922893 "{f}",
2893 .{diag},
2894 .{errors},
28942895 );
28952896 }
28962897 {
2897 var diag: Diagnostics = .init(arena);
2898 var errors: Errors = .init(arena);
28982899 try std.testing.expectError(error.ParseZon, fromSlice(i66, .{
28992900 .gpa = gpa,
29002901 .source = "-36893488147419103233",
2901 .diag = &diag,
2902 .errors = &errors,
29022903 }));
29032904 try std.testing.expectFmt(
29042905 "1:1: error: type 'i66' cannot represent value\n",
29052906 "{f}",
2906 .{diag},
2907 .{errors},
29072908 );
29082909 }
29092910
......@@ -2911,224 +2912,224 @@ test "std.zon parse int" {
29112912 try std.testing.expectEqual(@as(i8, -1), try fromSlice(i8, .{
29122913 .gpa = gpa,
29132914 .source = "-1.0",
2914 .diag = null,
2915 .errors = null,
29152916 }));
29162917 try std.testing.expectEqual(@as(i8, 123), try fromSlice(i8, .{
29172918 .gpa = gpa,
29182919 .source = "123.0",
2919 .diag = null,
2920 .errors = null,
29202921 }));
29212922
29222923 // Test non-decimal integers
29232924 try std.testing.expectEqual(@as(i16, 0xff), try fromSlice(i16, .{
29242925 .gpa = gpa,
29252926 .source = "0xff",
2926 .diag = null,
2927 .errors = null,
29272928 }));
29282929 try std.testing.expectEqual(@as(i16, -0xff), try fromSlice(i16, .{
29292930 .gpa = gpa,
29302931 .source = "-0xff",
2931 .diag = null,
2932 .errors = null,
29322933 }));
29332934 try std.testing.expectEqual(@as(i16, 0o77), try fromSlice(i16, .{
29342935 .gpa = gpa,
29352936 .source = "0o77",
2936 .diag = null,
2937 .errors = null,
29372938 }));
29382939 try std.testing.expectEqual(@as(i16, -0o77), try fromSlice(i16, .{
29392940 .gpa = gpa,
29402941 .source = "-0o77",
2941 .diag = null,
2942 .errors = null,
29422943 }));
29432944 try std.testing.expectEqual(@as(i16, 0b11), try fromSlice(i16, .{
29442945 .gpa = gpa,
29452946 .source = "0b11",
2946 .diag = null,
2947 .errors = null,
29472948 }));
29482949 try std.testing.expectEqual(@as(i16, -0b11), try fromSlice(i16, .{
29492950 .gpa = gpa,
29502951 .source = "-0b11",
2951 .diag = null,
2952 .errors = null,
29522953 }));
29532954
29542955 // Test non-decimal big integers
29552956 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSlice(u65, .{
29562957 .gpa = gpa,
29572958 .source = "0x1ffffffffffffffff",
2958 .diag = null,
2959 .errors = null,
29592960 }));
29602961 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSlice(i66, .{
29612962 .gpa = gpa,
29622963 .source = "0x1ffffffffffffffff",
2963 .diag = null,
2964 .errors = null,
29642965 }));
29652966 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSlice(i66, .{
29662967 .gpa = gpa,
29672968 .source = "-0x1ffffffffffffffff",
2968 .diag = null,
2969 .errors = null,
29692970 }));
29702971 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSlice(u65, .{
29712972 .gpa = gpa,
29722973 .source = "0o3777777777777777777777",
2973 .diag = null,
2974 .errors = null,
29742975 }));
29752976 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSlice(i66, .{
29762977 .gpa = gpa,
29772978 .source = "0o3777777777777777777777",
2978 .diag = null,
2979 .errors = null,
29792980 }));
29802981 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSlice(i66, .{
29812982 .gpa = gpa,
29822983 .source = "-0o3777777777777777777777",
2983 .diag = null,
2984 .errors = null,
29842985 }));
29852986 try std.testing.expectEqual(@as(u65, 0x1ffffffffffffffff), try fromSlice(u65, .{
29862987 .gpa = gpa,
29872988 .source = "0b11111111111111111111111111111111111111111111111111111111111111111",
2988 .diag = null,
2989 .errors = null,
29892990 }));
29902991 try std.testing.expectEqual(@as(i66, 0x1ffffffffffffffff), try fromSlice(i66, .{
29912992 .gpa = gpa,
29922993 .source = "0b11111111111111111111111111111111111111111111111111111111111111111",
2993 .diag = null,
2994 .errors = null,
29942995 }));
29952996 try std.testing.expectEqual(@as(i66, -0x1ffffffffffffffff), try fromSlice(i66, .{
29962997 .gpa = gpa,
29972998 .source = "-0b11111111111111111111111111111111111111111111111111111111111111111",
2998 .diag = null,
2999 .errors = null,
29993000 }));
30003001
30013002 // Number with invalid character in the middle
30023003 {
3003 var diag: Diagnostics = .init(arena);
3004 var errors: Errors = .init(arena);
30043005 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
30053006 .gpa = gpa,
30063007 .source = "32a32",
3007 .diag = &diag,
3008 .errors = &errors,
30083009 }));
30093010 try std.testing.expectFmt(
30103011 "1:3: error: invalid digit 'a' for decimal base\n",
30113012 "{f}",
3012 .{diag},
3013 .{errors},
30133014 );
30143015 }
30153016
30163017 // Failing to parse as int
30173018 {
3018 var diag: Diagnostics = .init(arena);
3019 var errors: Errors = .init(arena);
30193020 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
30203021 .gpa = gpa,
30213022 .source = "true",
3022 .diag = &diag,
3023 .errors = &errors,
30233024 }));
3024 try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{f}", .{diag});
3025 try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{f}", .{errors});
30253026 }
30263027
30273028 // Failing because an int is out of range
30283029 {
3029 var diag: Diagnostics = .init(arena);
3030 var errors: Errors = .init(arena);
30303031 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
30313032 .gpa = gpa,
30323033 .source = "256",
3033 .diag = &diag,
3034 .errors = &errors,
30343035 }));
30353036 try std.testing.expectFmt(
30363037 "1:1: error: type 'u8' cannot represent value\n",
30373038 "{f}",
3038 .{diag},
3039 .{errors},
30393040 );
30403041 }
30413042
30423043 // Failing because a negative int is out of range
30433044 {
3044 var diag: Diagnostics = .init(arena);
3045 var errors: Errors = .init(arena);
30453046 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
30463047 .gpa = gpa,
30473048 .source = "-129",
3048 .diag = &diag,
3049 .errors = &errors,
30493050 }));
30503051 try std.testing.expectFmt(
30513052 "1:1: error: type 'i8' cannot represent value\n",
30523053 "{f}",
3053 .{diag},
3054 .{errors},
30543055 );
30553056 }
30563057
30573058 // Failing because an unsigned int is negative
30583059 {
3059 var diag: Diagnostics = .init(arena);
3060 var errors: Errors = .init(arena);
30603061 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
30613062 .gpa = gpa,
30623063 .source = "-1",
3063 .diag = &diag,
3064 .errors = &errors,
30643065 }));
30653066 try std.testing.expectFmt(
30663067 "1:1: error: type 'u8' cannot represent value\n",
30673068 "{f}",
3068 .{diag},
3069 .{errors},
30693070 );
30703071 }
30713072
30723073 // Failing because a float is non-whole
30733074 {
3074 var diag: Diagnostics = .init(arena);
3075 var errors: Errors = .init(arena);
30753076 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
30763077 .gpa = gpa,
30773078 .source = "1.5",
3078 .diag = &diag,
3079 .errors = &errors,
30793080 }));
30803081 try std.testing.expectFmt(
30813082 "1:1: error: type 'u8' cannot represent value\n",
30823083 "{f}",
3083 .{diag},
3084 .{errors},
30843085 );
30853086 }
30863087
30873088 // Failing because a float is negative
30883089 {
3089 var diag: Diagnostics = .init(arena);
3090 var errors: Errors = .init(arena);
30903091 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
30913092 .gpa = gpa,
30923093 .source = "-1.0",
3093 .diag = &diag,
3094 .errors = &errors,
30943095 }));
30953096 try std.testing.expectFmt(
30963097 "1:1: error: type 'u8' cannot represent value\n",
30973098 "{f}",
3098 .{diag},
3099 .{errors},
30993100 );
31003101 }
31013102
31023103 // Negative integer zero
31033104 {
3104 var diag: Diagnostics = .init(arena);
3105 var errors: Errors = .init(arena);
31053106 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
31063107 .gpa = gpa,
31073108 .source = "-0",
3108 .diag = &diag,
3109 .errors = &errors,
31093110 }));
31103111 try std.testing.expectFmt(
31113112 \\1:2: error: integer literal '-0' is ambiguous
31123113 \\1:2: note: use '0' for an integer zero
31133114 \\1:2: note: use '-0.0' for a floating-point signed zero
31143115 \\
3115 , "{f}", .{diag});
3116 , "{f}", .{errors});
31163117 }
31173118
31183119 // Negative integer zero casted to float
31193120 {
3120 var diag: Diagnostics = .init(arena);
3121 var errors: Errors = .init(arena);
31213122 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
31223123 .gpa = gpa,
31233124 .source = "-0",
3124 .diag = &diag,
3125 .errors = &errors,
31253126 }));
31263127 try std.testing.expectFmt(
31273128 \\1:2: error: integer literal '-0' is ambiguous
31283129 \\1:2: note: use '0' for an integer zero
31293130 \\1:2: note: use '-0.0' for a floating-point signed zero
31303131 \\
3131 , "{f}", .{diag});
3132 , "{f}", .{errors});
31323133 }
31333134
31343135 // Negative float 0 is allowed
......@@ -3136,71 +3137,71 @@ test "std.zon parse int" {
31363137 std.math.isNegativeZero(try fromSlice(f32, .{
31373138 .gpa = gpa,
31383139 .source = "-0.0",
3139 .diag = null,
3140 .errors = null,
31403141 })),
31413142 );
31423143 try std.testing.expect(std.math.isPositiveZero(try fromSlice(f32, .{
31433144 .gpa = gpa,
31443145 .source = "0.0",
3145 .diag = null,
3146 .errors = null,
31463147 })));
31473148
31483149 // Double negation is not allowed
31493150 {
3150 var diag: Diagnostics = .init(arena);
3151 var errors: Errors = .init(arena);
31513152 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
31523153 .gpa = gpa,
31533154 .source = "--2",
3154 .diag = &diag,
3155 .errors = &errors,
31553156 }));
31563157 try std.testing.expectFmt(
31573158 "1:1: error: expected number or 'inf' after '-'\n",
31583159 "{f}",
3159 .{diag},
3160 .{errors},
31603161 );
31613162 }
31623163
31633164 {
3164 var diag: Diagnostics = .init(arena);
3165 var errors: Errors = .init(arena);
31653166 try std.testing.expectError(
31663167 error.ParseZon,
31673168 fromSlice(f32, .{
31683169 .gpa = gpa,
31693170 .source = "--2.0",
3170 .diag = &diag,
3171 .errors = &errors,
31713172 }),
31723173 );
31733174 try std.testing.expectFmt(
31743175 "1:1: error: expected number or 'inf' after '-'\n",
31753176 "{f}",
3176 .{diag},
3177 .{errors},
31773178 );
31783179 }
31793180
31803181 // Invalid int literal
31813182 {
3182 var diag: Diagnostics = .init(arena);
3183 var errors: Errors = .init(arena);
31833184 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
31843185 .gpa = gpa,
31853186 .source = "0xg",
3186 .diag = &diag,
3187 .errors = &errors,
31873188 }));
3188 try std.testing.expectFmt("1:3: error: invalid digit 'g' for hex base\n", "{f}", .{diag});
3189 try std.testing.expectFmt("1:3: error: invalid digit 'g' for hex base\n", "{f}", .{errors});
31893190 }
31903191
31913192 // Notes on invalid int literal
31923193 {
3193 var diag: Diagnostics = .init(arena);
3194 var errors: Errors = .init(arena);
31943195 try std.testing.expectError(error.ParseZon, fromSlice(u8, .{
31953196 .gpa = gpa,
31963197 .source = "0123",
3197 .diag = &diag,
3198 .errors = &errors,
31983199 }));
31993200 try std.testing.expectFmt(
32003201 \\1:1: error: number '0123' has leading zero
32013202 \\1:1: note: use '0o' prefix for octal literals
32023203 \\
3203 , "{f}", .{diag});
3204 , "{f}", .{errors});
32043205 }
32053206}
32063207
......@@ -3211,29 +3212,29 @@ test "std.zon negative char" {
32113212 const arena = arena_allocator.allocator();
32123213
32133214 {
3214 var diag: Diagnostics = .init(arena);
3215 var errors: Errors = .init(arena);
32153216 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
32163217 .gpa = gpa,
32173218 .source = "-'a'",
3218 .diag = &diag,
3219 .errors = &errors,
32193220 }));
32203221 try std.testing.expectFmt(
32213222 "1:1: error: expected number or 'inf' after '-'\n",
32223223 "{f}",
3223 .{diag},
3224 .{errors},
32243225 );
32253226 }
32263227 {
3227 var diag: Diagnostics = .init(arena);
3228 var errors: Errors = .init(arena);
32283229 try std.testing.expectError(error.ParseZon, fromSlice(i16, .{
32293230 .gpa = gpa,
32303231 .source = "-'a'",
3231 .diag = &diag,
3232 .errors = &errors,
32323233 }));
32333234 try std.testing.expectFmt(
32343235 "1:1: error: expected number or 'inf' after '-'\n",
32353236 "{f}",
3236 .{diag},
3237 .{errors},
32373238 );
32383239 }
32393240}
......@@ -3248,14 +3249,14 @@ test "std.zon parse float" {
32483249 try std.testing.expectEqual(@as(f16, 0.5), try fromSlice(f16, .{
32493250 .gpa = gpa,
32503251 .source = "0.5",
3251 .diag = null,
3252 .errors = null,
32523253 }));
32533254 try std.testing.expectEqual(
32543255 @as(f32, 123.456),
32553256 try fromSlice(f32, .{
32563257 .gpa = gpa,
32573258 .source = "123.456",
3258 .diag = null,
3259 .errors = null,
32593260 }),
32603261 );
32613262 try std.testing.expectEqual(
......@@ -3263,47 +3264,47 @@ test "std.zon parse float" {
32633264 try fromSlice(f64, .{
32643265 .gpa = gpa,
32653266 .source = "-123.456",
3266 .diag = null,
3267 .errors = null,
32673268 }),
32683269 );
32693270 try std.testing.expectEqual(@as(f128, 42.5), try fromSlice(f128, .{
32703271 .gpa = gpa,
32713272 .source = "42.5",
3272 .diag = null,
3273 .errors = null,
32733274 }));
32743275
32753276 // Test whole numbers with and without decimals
32763277 try std.testing.expectEqual(@as(f16, 5.0), try fromSlice(f16, .{
32773278 .gpa = gpa,
32783279 .source = "5.0",
3279 .diag = null,
3280 .errors = null,
32803281 }));
32813282 try std.testing.expectEqual(@as(f16, 5.0), try fromSlice(f16, .{
32823283 .gpa = gpa,
32833284 .source = "5",
3284 .diag = null,
3285 .errors = null,
32853286 }));
32863287 try std.testing.expectEqual(@as(f32, -102), try fromSlice(f32, .{
32873288 .gpa = gpa,
32883289 .source = "-102.0",
3289 .diag = null,
3290 .errors = null,
32903291 }));
32913292 try std.testing.expectEqual(@as(f32, -102), try fromSlice(f32, .{
32923293 .gpa = gpa,
32933294 .source = "-102",
3294 .diag = null,
3295 .errors = null,
32953296 }));
32963297
32973298 // Test characters and negated characters
32983299 try std.testing.expectEqual(@as(f32, 'a'), try fromSlice(f32, .{
32993300 .gpa = gpa,
33003301 .source = "'a'",
3301 .diag = null,
3302 .errors = null,
33023303 }));
33033304 try std.testing.expectEqual(@as(f32, 'z'), try fromSlice(f32, .{
33043305 .gpa = gpa,
33053306 .source = "'z'",
3306 .diag = null,
3307 .errors = null,
33073308 }));
33083309
33093310 // Test big integers
......@@ -3312,7 +3313,7 @@ test "std.zon parse float" {
33123313 try fromSlice(f32, .{
33133314 .gpa = gpa,
33143315 .source = "36893488147419103231",
3315 .diag = null,
3316 .errors = null,
33163317 }),
33173318 );
33183319 try std.testing.expectEqual(
......@@ -3320,18 +3321,18 @@ test "std.zon parse float" {
33203321 try fromSlice(f32, .{
33213322 .gpa = gpa,
33223323 .source = "-36893488147419103231",
3323 .diag = null,
3324 .errors = null,
33243325 }),
33253326 );
33263327 try std.testing.expectEqual(@as(f128, 0x1ffffffffffffffff), try fromSlice(f128, .{
33273328 .gpa = gpa,
33283329 .source = "0x1ffffffffffffffff",
3329 .diag = null,
3330 .errors = null,
33303331 }));
33313332 try std.testing.expectEqual(@as(f32, @floatFromInt(0x1ffffffffffffffff)), try fromSlice(f32, .{
33323333 .gpa = gpa,
33333334 .source = "0x1ffffffffffffffff",
3334 .diag = null,
3335 .errors = null,
33353336 }));
33363337
33373338 // Exponents, underscores
......@@ -3340,7 +3341,7 @@ test "std.zon parse float" {
33403341 try fromSlice(f32, .{
33413342 .gpa = gpa,
33423343 .source = "12_3.0E+77",
3343 .diag = null,
3344 .errors = null,
33443345 }),
33453346 );
33463347
......@@ -3350,7 +3351,7 @@ test "std.zon parse float" {
33503351 try fromSlice(f32, .{
33513352 .gpa = gpa,
33523353 .source = "0x103.70p-5",
3353 .diag = null,
3354 .errors = null,
33543355 }),
33553356 );
33563357 try std.testing.expectEqual(
......@@ -3358,7 +3359,7 @@ test "std.zon parse float" {
33583359 try fromSlice(f32, .{
33593360 .gpa = gpa,
33603361 .source = "-0x103.70",
3361 .diag = null,
3362 .errors = null,
33623363 }),
33633364 );
33643365 try std.testing.expectEqual(
......@@ -3366,7 +3367,7 @@ test "std.zon parse float" {
33663367 try fromSlice(f32, .{
33673368 .gpa = gpa,
33683369 .source = "0x1234_5678.9ABC_CDEFp-10",
3369 .diag = null,
3370 .errors = null,
33703371 }),
33713372 );
33723373
......@@ -3374,120 +3375,120 @@ test "std.zon parse float" {
33743375 try std.testing.expect(std.math.isPositiveInf(try fromSlice(f32, .{
33753376 .gpa = gpa,
33763377 .source = "inf",
3377 .diag = null,
3378 .errors = null,
33783379 })));
33793380 try std.testing.expect(std.math.isNegativeInf(try fromSlice(f32, .{
33803381 .gpa = gpa,
33813382 .source = "-inf",
3382 .diag = null,
3383 .errors = null,
33833384 })));
33843385 try std.testing.expect(std.math.isNan(try fromSlice(f32, .{
33853386 .gpa = gpa,
33863387 .source = "nan",
3387 .diag = null,
3388 .errors = null,
33883389 })));
33893390
33903391 // Negative nan not allowed
33913392 {
3392 var diag: Diagnostics = .init(arena);
3393 var errors: Errors = .init(arena);
33933394 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
33943395 .gpa = gpa,
33953396 .source = "-nan",
3396 .diag = &diag,
3397 .errors = &errors,
33973398 }));
33983399 try std.testing.expectFmt(
33993400 "1:1: error: expected number or 'inf' after '-'\n",
34003401 "{f}",
3401 .{diag},
3402 .{errors},
34023403 );
34033404 }
34043405
34053406 // nan as int not allowed
34063407 {
3407 var diag: Diagnostics = .init(arena);
3408 var errors: Errors = .init(arena);
34083409 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
34093410 .gpa = gpa,
34103411 .source = "nan",
3411 .diag = &diag,
3412 .errors = &errors,
34123413 }));
3413 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{diag});
3414 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{errors});
34143415 }
34153416
34163417 // nan as int not allowed
34173418 {
3418 var diag: Diagnostics = .init(arena);
3419 var errors: Errors = .init(arena);
34193420 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
34203421 .gpa = gpa,
34213422 .source = "nan",
3422 .diag = &diag,
3423 .errors = &errors,
34233424 }));
3424 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{diag});
3425 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{errors});
34253426 }
34263427
34273428 // inf as int not allowed
34283429 {
3429 var diag: Diagnostics = .init(arena);
3430 var errors: Errors = .init(arena);
34303431 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
34313432 .gpa = gpa,
34323433 .source = "inf",
3433 .diag = &diag,
3434 .errors = &errors,
34343435 }));
3435 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{diag});
3436 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{errors});
34363437 }
34373438
34383439 // -inf as int not allowed
34393440 {
3440 var diag: Diagnostics = .init(arena);
3441 var errors: Errors = .init(arena);
34413442 try std.testing.expectError(error.ParseZon, fromSlice(i8, .{
34423443 .gpa = gpa,
34433444 .source = "-inf",
3444 .diag = &diag,
3445 .errors = &errors,
34453446 }));
3446 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{diag});
3447 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{f}", .{errors});
34473448 }
34483449
34493450 // Bad identifier as float
34503451 {
3451 var diag: Diagnostics = .init(arena);
3452 var errors: Errors = .init(arena);
34523453 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
34533454 .gpa = gpa,
34543455 .source = "foo",
3455 .diag = &diag,
3456 .errors = &errors,
34563457 }));
34573458 try std.testing.expectFmt(
34583459 \\1:1: error: invalid expression
34593460 \\1:1: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
34603461 \\1:1: note: precede identifier with '.' for an enum literal
34613462 \\
3462 , "{f}", .{diag});
3463 , "{f}", .{errors});
34633464 }
34643465
34653466 {
3466 var diag: Diagnostics = .init(arena);
3467 var errors: Errors = .init(arena);
34673468 try std.testing.expectError(error.ParseZon, fromSlice(f32, .{
34683469 .gpa = gpa,
34693470 .source = "-foo",
3470 .diag = &diag,
3471 .errors = &errors,
34713472 }));
34723473 try std.testing.expectFmt(
34733474 "1:1: error: expected number or 'inf' after '-'\n",
34743475 "{f}",
3475 .{diag},
3476 .{errors},
34763477 );
34773478 }
34783479
34793480 // Non float as float
34803481 {
3481 var diag: Diagnostics = .init(arena);
3482 var errors: Errors = .init(arena);
34823483 try std.testing.expectError(
34833484 error.ParseZon,
34843485 fromSlice(f32, .{
34853486 .gpa = gpa,
34863487 .source = "\"foo\"",
3487 .diag = &diag,
3488 .errors = &errors,
34883489 }),
34893490 );
3490 try std.testing.expectFmt("1:1: error: expected type 'f32'\n", "{f}", .{diag});
3491 try std.testing.expectFmt("1:1: error: expected type 'f32'\n", "{f}", .{errors});
34913492 }
34923493}
34933494
......@@ -3514,7 +3515,7 @@ test "std.zon free on error" {
35143515 \\ .z = "fail",
35153516 \\}
35163517 ,
3517 .diag = null,
3518 .errors = null,
35183519 }));
35193520 }
35203521
......@@ -3535,7 +3536,7 @@ test "std.zon free on error" {
35353536 \\ "fail",
35363537 \\}
35373538 ,
3538 .diag = null,
3539 .errors = null,
35393540 }));
35403541 }
35413542
......@@ -3552,7 +3553,7 @@ test "std.zon free on error" {
35523553 \\ .x = "hello",
35533554 \\}
35543555 ,
3555 .diag = null,
3556 .errors = null,
35563557 }));
35573558
35583559 // Test freeing partially allocated arrays
......@@ -3566,7 +3567,7 @@ test "std.zon free on error" {
35663567 \\ false,
35673568 \\}
35683569 ,
3569 .diag = null,
3570 .errors = null,
35703571 }));
35713572
35723573 // Test freeing partially allocated slices
......@@ -3580,7 +3581,7 @@ test "std.zon free on error" {
35803581 \\ false,
35813582 \\}
35823583 ,
3583 .diag = null,
3584 .errors = null,
35843585 }));
35853586
35863587 // We can parse types that can't be freed, as long as they contain no allocations, e.g. untagged
......@@ -3590,7 +3591,7 @@ test "std.zon free on error" {
35903591 (try fromSlice(union { x: f32 }, .{
35913592 .gpa = gpa,
35923593 .source = ".{ .x = 1.5 }",
3593 .diag = null,
3594 .errors = null,
35943595 })).x,
35953596 );
35963597
......@@ -3601,7 +3602,7 @@ test "std.zon free on error" {
36013602 .gpa = gpa,
36023603 .arena = arena,
36033604 .source = ".{ .x = \"foo\" }",
3604 .diag = null,
3605 .errors = null,
36053606 });
36063607 try std.testing.expectEqualStrings("foo", result.x);
36073608 }
......@@ -3622,7 +3623,7 @@ test "std.zon vector" {
36223623 try fromSlice(@Vector(0, bool), .{
36233624 .gpa = gpa,
36243625 .source = ".{}",
3625 .diag = null,
3626 .errors = null,
36263627 }),
36273628 );
36283629 try std.testing.expectEqual(
......@@ -3630,7 +3631,7 @@ test "std.zon vector" {
36303631 try fromSlice(@Vector(3, bool), .{
36313632 .gpa = gpa,
36323633 .source = ".{true, false, true}",
3633 .diag = null,
3634 .errors = null,
36343635 }),
36353636 );
36363637
......@@ -3639,7 +3640,7 @@ test "std.zon vector" {
36393640 try fromSlice(@Vector(0, f32), .{
36403641 .gpa = gpa,
36413642 .source = ".{}",
3642 .diag = null,
3643 .errors = null,
36433644 }),
36443645 );
36453646 try std.testing.expectEqual(
......@@ -3647,7 +3648,7 @@ test "std.zon vector" {
36473648 try fromSlice(@Vector(3, f32), .{
36483649 .gpa = gpa,
36493650 .source = ".{1.5, 2.5, 3.5}",
3650 .diag = null,
3651 .errors = null,
36513652 }),
36523653 );
36533654
......@@ -3656,7 +3657,7 @@ test "std.zon vector" {
36563657 try fromSlice(@Vector(0, u8), .{
36573658 .gpa = gpa,
36583659 .source = ".{}",
3659 .diag = null,
3660 .errors = null,
36603661 }),
36613662 );
36623663 try std.testing.expectEqual(
......@@ -3664,7 +3665,7 @@ test "std.zon vector" {
36643665 try fromSlice(@Vector(3, u8), .{
36653666 .gpa = gpa,
36663667 .source = ".{2, 4, 6}",
3667 .diag = null,
3668 .errors = null,
36683669 }),
36693670 );
36703671
......@@ -3675,14 +3676,14 @@ test "std.zon vector" {
36753676 .gpa = gpa,
36763677 .arena = arena,
36773678 .source = ".{}",
3678 .diag = null,
3679 .errors = null,
36793680 }),
36803681 );
36813682 const pointers = try fromSliceAlloc(@Vector(3, *const u8), .{
36823683 .gpa = gpa,
36833684 .arena = arena,
36843685 .source = ".{2, 4, 6}",
3685 .diag = null,
3686 .errors = null,
36863687 });
36873688 try std.testing.expectEqualDeep(@Vector(3, *const u8){ &2, &4, &6 }, pointers);
36883689 }
......@@ -3694,99 +3695,99 @@ test "std.zon vector" {
36943695 .gpa = gpa,
36953696 .arena = arena,
36963697 .source = ".{}",
3697 .diag = null,
3698 .errors = null,
36983699 }),
36993700 );
37003701 const pointers = try fromSliceAlloc(@Vector(3, ?*const u8), .{
37013702 .gpa = gpa,
37023703 .arena = arena,
37033704 .source = ".{2, null, 6}",
3704 .diag = null,
3705 .errors = null,
37053706 });
37063707 try std.testing.expectEqualDeep(@Vector(3, ?*const u8){ &2, null, &6 }, pointers);
37073708 }
37083709
37093710 // Too few fields
37103711 {
3711 var diag: Diagnostics = .init(arena);
3712 var errors: Errors = .init(arena);
37123713 try std.testing.expectError(
37133714 error.ParseZon,
37143715 fromSlice(@Vector(2, f32), .{
37153716 .gpa = gpa,
37163717 .source = ".{0.5}",
3717 .diag = &diag,
3718 .errors = &errors,
37183719 }),
37193720 );
37203721 try std.testing.expectFmt(
37213722 "1:2: error: expected 2 array elements; found 1\n",
37223723 "{f}",
3723 .{diag},
3724 .{errors},
37243725 );
37253726 }
37263727
37273728 // Too many fields
37283729 {
3729 var diag: Diagnostics = .init(arena);
3730 var errors: Errors = .init(arena);
37303731 try std.testing.expectError(
37313732 error.ParseZon,
37323733 fromSlice(@Vector(2, f32), .{
37333734 .gpa = gpa,
37343735 .source = ".{0.5, 1.5, 2.5}",
3735 .diag = &diag,
3736 .errors = &errors,
37363737 }),
37373738 );
37383739 try std.testing.expectFmt(
37393740 "1:13: error: index 2 outside of array of length 2\n",
37403741 "{f}",
3741 .{diag},
3742 .{errors},
37423743 );
37433744 }
37443745
37453746 // Wrong type fields
37463747 {
3747 var diag: Diagnostics = .init(arena);
3748 var errors: Errors = .init(arena);
37483749 try std.testing.expectError(
37493750 error.ParseZon,
37503751 fromSlice(@Vector(3, f32), .{
37513752 .gpa = gpa,
37523753 .source = ".{0.5, true, 2.5}",
3753 .diag = &diag,
3754 .errors = &errors,
37543755 }),
37553756 );
37563757 try std.testing.expectFmt(
37573758 "1:8: error: expected type 'f32'\n",
37583759 "{f}",
3759 .{diag},
3760 .{errors},
37603761 );
37613762 }
37623763
37633764 // Wrong type
37643765 {
3765 var diag: Diagnostics = .init(arena);
3766 var errors: Errors = .init(arena);
37663767 try std.testing.expectError(
37673768 error.ParseZon,
37683769 fromSlice(@Vector(3, u8), .{
37693770 .gpa = gpa,
37703771 .source = "true",
3771 .diag = &diag,
3772 .errors = &errors,
37723773 }),
37733774 );
3774 try std.testing.expectFmt("1:1: error: expected type '@Vector(3, u8)'\n", "{f}", .{diag});
3775 try std.testing.expectFmt("1:1: error: expected type '@Vector(3, u8)'\n", "{f}", .{errors});
37753776 }
37763777
37773778 // Elements should get freed on error
37783779 {
3779 var diag: Diagnostics = .init(arena);
3780 var errors: Errors = .init(arena);
37803781 try std.testing.expectError(
37813782 error.ParseZon,
37823783 fromSliceAlloc(@Vector(3, *u8), .{
37833784 .gpa = gpa,
37843785 .arena = arena,
37853786 .source = ".{1, true, 3}",
3786 .diag = &diag,
3787 .errors = &errors,
37873788 }),
37883789 );
3789 try std.testing.expectFmt("1:6: error: expected type 'u8'\n", "{f}", .{diag});
3790 try std.testing.expectFmt("1:6: error: expected type 'u8'\n", "{f}", .{errors});
37903791 }
37913792}
37923793
......@@ -3802,7 +3803,7 @@ test "std.zon add pointers" {
38023803 .gpa = gpa,
38033804 .arena = arena,
38043805 .source = "10",
3805 .diag = null,
3806 .errors = null,
38063807 });
38073808 try std.testing.expectEqual(@as(u32, 10), result.*);
38083809 }
......@@ -3812,7 +3813,7 @@ test "std.zon add pointers" {
38123813 .gpa = gpa,
38133814 .arena = arena,
38143815 .source = "10",
3815 .diag = null,
3816 .errors = null,
38163817 });
38173818 try std.testing.expectEqual(@as(u32, 10), result.*.*);
38183819 }
......@@ -3822,7 +3823,7 @@ test "std.zon add pointers" {
38223823 .gpa = gpa,
38233824 .arena = arena,
38243825 .source = "10",
3825 .diag = null,
3826 .errors = null,
38263827 });
38273828 try std.testing.expectEqual(@as(u32, 10), result.*.*.*);
38283829 }
......@@ -3833,7 +3834,7 @@ test "std.zon add pointers" {
38333834 .gpa = gpa,
38343835 .arena = arena,
38353836 .source = "10",
3836 .diag = null,
3837 .errors = null,
38373838 });
38383839 try std.testing.expectEqual(@as(u32, 10), some.?.*);
38393840
......@@ -3841,7 +3842,7 @@ test "std.zon add pointers" {
38413842 .gpa = gpa,
38423843 .arena = arena,
38433844 .source = "null",
3844 .diag = null,
3845 .errors = null,
38453846 });
38463847 try std.testing.expectEqual(null, none);
38473848 }
......@@ -3851,7 +3852,7 @@ test "std.zon add pointers" {
38513852 .gpa = gpa,
38523853 .arena = arena,
38533854 .source = "10",
3854 .diag = null,
3855 .errors = null,
38553856 });
38563857 try std.testing.expectEqual(@as(u32, 10), some.*.?);
38573858
......@@ -3859,7 +3860,7 @@ test "std.zon add pointers" {
38593860 .gpa = gpa,
38603861 .arena = arena,
38613862 .source = "null",
3862 .diag = null,
3863 .errors = null,
38633864 });
38643865 try std.testing.expectEqual(null, none.*);
38653866 }
......@@ -3869,7 +3870,7 @@ test "std.zon add pointers" {
38693870 .gpa = gpa,
38703871 .arena = arena,
38713872 .source = "10",
3872 .diag = null,
3873 .errors = null,
38733874 });
38743875 try std.testing.expectEqual(@as(u32, 10), some.?.*.*);
38753876
......@@ -3877,7 +3878,7 @@ test "std.zon add pointers" {
38773878 .gpa = gpa,
38783879 .arena = arena,
38793880 .source = "null",
3880 .diag = null,
3881 .errors = null,
38813882 });
38823883 try std.testing.expectEqual(null, none);
38833884 }
......@@ -3887,7 +3888,7 @@ test "std.zon add pointers" {
38873888 .gpa = gpa,
38883889 .arena = arena,
38893890 .source = "10",
3890 .diag = null,
3891 .errors = null,
38913892 });
38923893 try std.testing.expectEqual(@as(u32, 10), some.*.?.*);
38933894
......@@ -3895,7 +3896,7 @@ test "std.zon add pointers" {
38953896 .gpa = gpa,
38963897 .arena = arena,
38973898 .source = "null",
3898 .diag = null,
3899 .errors = null,
38993900 });
39003901 try std.testing.expectEqual(null, none.*);
39013902 }
......@@ -3905,7 +3906,7 @@ test "std.zon add pointers" {
39053906 .gpa = gpa,
39063907 .arena = arena,
39073908 .source = "10",
3908 .diag = null,
3909 .errors = null,
39093910 });
39103911 try std.testing.expectEqual(@as(u32, 10), some.*.*.?);
39113912
......@@ -3913,7 +3914,7 @@ test "std.zon add pointers" {
39133914 .gpa = gpa,
39143915 .arena = arena,
39153916 .source = "null",
3916 .diag = null,
3917 .errors = null,
39173918 });
39183919 try std.testing.expectEqual(null, none.*.*);
39193920 }
......@@ -3924,7 +3925,7 @@ test "std.zon add pointers" {
39243925 .gpa = gpa,
39253926 .arena = arena,
39263927 .source = ".{ 1, 2, 3 }",
3927 .diag = null,
3928 .errors = null,
39283929 });
39293930 try std.testing.expectEqual([3]u8{ 1, 2, 3 }, result.*);
39303931 }
......@@ -3959,7 +3960,7 @@ test "std.zon add pointers" {
39593960 \\ .f2 = null,
39603961 \\}
39613962 ,
3962 .diag = null,
3963 .errors = null,
39633964 });
39643965
39653966 try std.testing.expectEqualDeep(expected, found.?.*);
......@@ -3967,185 +3968,185 @@ test "std.zon add pointers" {
39673968
39683969 // Test that optional types are flattened correctly in errors
39693970 {
3970 var diag: Diagnostics = .init(arena);
3971 var errors: Errors = .init(arena);
39713972 try std.testing.expectError(
39723973 error.ParseZon,
39733974 fromSliceAlloc(*const ?*const u8, .{
39743975 .gpa = gpa,
39753976 .arena = arena,
39763977 .source = "true",
3977 .diag = &diag,
3978 .errors = &errors,
39783979 }),
39793980 );
3980 try std.testing.expectFmt("1:1: error: expected type '?u8'\n", "{f}", .{diag});
3981 try std.testing.expectFmt("1:1: error: expected type '?u8'\n", "{f}", .{errors});
39813982 }
39823983
39833984 {
3984 var diag: Diagnostics = .init(arena);
3985 var errors: Errors = .init(arena);
39853986 try std.testing.expectError(
39863987 error.ParseZon,
39873988 fromSliceAlloc(*const ?*const f32, .{
39883989 .gpa = gpa,
39893990 .arena = arena,
39903991 .source = "true",
3991 .diag = &diag,
3992 .errors = &errors,
39923993 }),
39933994 );
3994 try std.testing.expectFmt("1:1: error: expected type '?f32'\n", "{f}", .{diag});
3995 try std.testing.expectFmt("1:1: error: expected type '?f32'\n", "{f}", .{errors});
39953996 }
39963997
39973998 {
3998 var diag: Diagnostics = .init(arena);
3999 var errors: Errors = .init(arena);
39994000 try std.testing.expectError(
40004001 error.ParseZon,
40014002 fromSliceAlloc(*const ?*const @Vector(3, u8), .{
40024003 .gpa = gpa,
40034004 .arena = arena,
40044005 .source = "true",
4005 .diag = &diag,
4006 .errors = &errors,
40064007 }),
40074008 );
4008 try std.testing.expectFmt("1:1: error: expected type '?@Vector(3, u8)'\n", "{f}", .{diag});
4009 try std.testing.expectFmt("1:1: error: expected type '?@Vector(3, u8)'\n", "{f}", .{errors});
40094010 }
40104011
40114012 {
4012 var diag: Diagnostics = .init(arena);
4013 var errors: Errors = .init(arena);
40134014 try std.testing.expectError(
40144015 error.ParseZon,
40154016 fromSliceAlloc(*const ?*const bool, .{
40164017 .gpa = gpa,
40174018 .arena = arena,
40184019 .source = "10",
4019 .diag = &diag,
4020 .errors = &errors,
40204021 }),
40214022 );
4022 try std.testing.expectFmt("1:1: error: expected type '?bool'\n", "{f}", .{diag});
4023 try std.testing.expectFmt("1:1: error: expected type '?bool'\n", "{f}", .{errors});
40234024 }
40244025
40254026 {
4026 var diag: Diagnostics = .init(arena);
4027 var errors: Errors = .init(arena);
40274028 try std.testing.expectError(
40284029 error.ParseZon,
40294030 fromSliceAlloc(*const ?*const struct { a: i32 }, .{
40304031 .gpa = gpa,
40314032 .arena = arena,
40324033 .source = "true",
4033 .diag = &diag,
4034 .errors = &errors,
40344035 }),
40354036 );
4036 try std.testing.expectFmt("1:1: error: expected optional struct\n", "{f}", .{diag});
4037 try std.testing.expectFmt("1:1: error: expected optional struct\n", "{f}", .{errors});
40374038 }
40384039
40394040 {
4040 var diag: Diagnostics = .init(arena);
4041 var errors: Errors = .init(arena);
40414042 try std.testing.expectError(
40424043 error.ParseZon,
40434044 fromSliceAlloc(*const ?*const struct { i32 }, .{
40444045 .gpa = gpa,
40454046 .arena = arena,
40464047 .source = "true",
4047 .diag = &diag,
4048 .errors = &errors,
40484049 }),
40494050 );
4050 try std.testing.expectFmt("1:1: error: expected optional tuple\n", "{f}", .{diag});
4051 try std.testing.expectFmt("1:1: error: expected optional tuple\n", "{f}", .{errors});
40514052 }
40524053
40534054 {
4054 var diag: Diagnostics = .init(arena);
4055 var errors: Errors = .init(arena);
40554056 try std.testing.expectError(
40564057 error.ParseZon,
40574058 fromSliceAlloc(*const ?*const union { x: void }, .{
40584059 .gpa = gpa,
40594060 .arena = arena,
40604061 .source = "true",
4061 .diag = &diag,
4062 .errors = &errors,
40624063 }),
40634064 );
4064 try std.testing.expectFmt("1:1: error: expected optional union\n", "{f}", .{diag});
4065 try std.testing.expectFmt("1:1: error: expected optional union\n", "{f}", .{errors});
40654066 }
40664067
40674068 {
4068 var diag: Diagnostics = .init(arena);
4069 var errors: Errors = .init(arena);
40694070 try std.testing.expectError(
40704071 error.ParseZon,
40714072 fromSliceAlloc(*const ?*const [3]u8, .{
40724073 .gpa = gpa,
40734074 .arena = arena,
40744075 .source = "true",
4075 .diag = &diag,
4076 .errors = &errors,
40764077 }),
40774078 );
4078 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{diag});
4079 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{errors});
40794080 }
40804081
40814082 {
4082 var diag: Diagnostics = .init(arena);
4083 var errors: Errors = .init(arena);
40834084 try std.testing.expectError(
40844085 error.ParseZon,
40854086 fromSliceAlloc(?[3]u8, .{
40864087 .gpa = gpa,
40874088 .arena = arena,
40884089 .source = "true",
4089 .diag = &diag,
4090 .errors = &errors,
40904091 }),
40914092 );
4092 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{diag});
4093 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{errors});
40934094 }
40944095
40954096 {
4096 var diag: Diagnostics = .init(arena);
4097 var errors: Errors = .init(arena);
40974098 try std.testing.expectError(
40984099 error.ParseZon,
40994100 fromSliceAlloc(*const ?*const []u8, .{
41004101 .gpa = gpa,
41014102 .arena = arena,
41024103 .source = "true",
4103 .diag = &diag,
4104 .errors = &errors,
41044105 }),
41054106 );
4106 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{diag});
4107 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{errors});
41074108 }
41084109
41094110 {
4110 var diag: Diagnostics = .init(arena);
4111 var errors: Errors = .init(arena);
41114112 try std.testing.expectError(
41124113 error.ParseZon,
41134114 fromSliceAlloc(?[]u8, .{
41144115 .gpa = gpa,
41154116 .arena = arena,
41164117 .source = "true",
4117 .diag = &diag,
4118 .errors = &errors,
41184119 }),
41194120 );
4120 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{diag});
4121 try std.testing.expectFmt("1:1: error: expected optional array\n", "{f}", .{errors});
41214122 }
41224123
41234124 {
4124 var diag: Diagnostics = .init(arena);
4125 var errors: Errors = .init(arena);
41254126 try std.testing.expectError(
41264127 error.ParseZon,
41274128 fromSliceAlloc(*const ?*const []const u8, .{
41284129 .gpa = gpa,
41294130 .arena = arena,
41304131 .source = "true",
4131 .diag = &diag,
4132 .errors = &errors,
41324133 }),
41334134 );
4134 try std.testing.expectFmt("1:1: error: expected optional string\n", "{f}", .{diag});
4135 try std.testing.expectFmt("1:1: error: expected optional string\n", "{f}", .{errors});
41354136 }
41364137
41374138 {
4138 var diag: Diagnostics = .init(arena);
4139 var errors: Errors = .init(arena);
41394140 try std.testing.expectError(
41404141 error.ParseZon,
41414142 fromSliceAlloc(*const ?*const enum { foo }, .{
41424143 .gpa = gpa,
41434144 .arena = arena,
41444145 .source = "true",
4145 .diag = &diag,
4146 .errors = &errors,
41464147 }),
41474148 );
4148 try std.testing.expectFmt("1:1: error: expected optional enum literal\n", "{f}", .{diag});
4149 try std.testing.expectFmt("1:1: error: expected optional enum literal\n", "{f}", .{errors});
41494150 }
41504151}
41514152
......@@ -4167,7 +4168,7 @@ test "std.zon stop on node" {
41674168 const result = try fromZoir(Vec2, .{
41684169 .ast = &ast,
41694170 .zoir = &zoir,
4170 .diag = null,
4171 .errors = null,
41714172 });
41724173
41734174 try std.testing.expectEqual(result.y, 2.5);
......@@ -4184,7 +4185,7 @@ test "std.zon stop on node" {
41844185 const result = try fromZoir(Zoir.Node.Index, .{
41854186 .ast = &ast,
41864187 .zoir = &zoir,
4187 .diag = null,
4188 .errors = null,
41884189 });
41894190 try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(&zoir));
41904191 }
......@@ -4198,7 +4199,7 @@ test "std.zon no alloc" {
41984199 try fromSlice([3]u8, .{
41994200 .gpa = gpa,
42004201 .source = ".{ 1, 2, 3 }",
4201 .diag = null,
4202 .errors = null,
42024203 }),
42034204 );
42044205
......@@ -4215,12 +4216,12 @@ test "std.zon no alloc" {
42154216 try fromZoir(Nested, .{
42164217 .ast = &ast,
42174218 .zoir = &zoir,
4218 .diag = null,
4219 .errors = null,
42194220 }),
42204221 );
42214222}
42224223
4223test "std.zon errors without diagnostics" {
4224test "std.zon errors without errorsnostics" {
42244225 const gpa = std.testing.allocator;
42254226 var arena_allocator: ArenaAllocator = .init(gpa);
42264227 defer arena_allocator.deinit();
......@@ -4235,7 +4236,7 @@ test "std.zon errors without diagnostics" {
42354236 .gpa = gpa,
42364237 .arena = arena,
42374238 .source = ".nothing",
4238 .diag = null,
4239 .errors = null,
42394240 }));
42404241
42414242 const Struct = struct {
......@@ -4245,7 +4246,7 @@ test "std.zon errors without diagnostics" {
42454246 .gpa = gpa,
42464247 .arena = arena,
42474248 .source = ".{ .name = \"Alice\", .age = 25 }",
4248 .diag = null,
4249 .errors = null,
42494250 }));
42504251
42514252 const Union = union(enum) {
......@@ -4256,13 +4257,13 @@ test "std.zon errors without diagnostics" {
42564257 .gpa = gpa,
42574258 .arena = arena,
42584259 .source = ".a",
4259 .diag = null,
4260 .errors = null,
42604261 }));
42614262 try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, .{
42624263 .gpa = gpa,
42634264 .arena = arena,
42644265 .source = ".{ .b = 8 }",
4265 .diag = null,
4266 .errors = null,
42664267 }));
42674268}
42684269
......@@ -4284,7 +4285,7 @@ test "std.zon aligned pointers" {
42844285 .gpa = gpa,
42854286 .arena = arena,
42864287 .source = ".{ .inner = 10 }",
4287 .diag = null,
4288 .errors = null,
42884289 });
42894290 try std.testing.expectEqualDeep(expected.inner, found.inner);
42904291}
......@@ -4329,7 +4330,7 @@ test "std.zon update basic" {
43294330 .gpa = gpa,
43304331 .arena = arena,
43314332 .source = ".{}",
4332 .diag = null,
4333 .errors = null,
43334334 });
43344335 try std.testing.expectEqualDeep(expected, found);
43354336
......@@ -4337,7 +4338,7 @@ test "std.zon update basic" {
43374338 .gpa = gpa,
43384339 .arena = arena,
43394340 .source = ".{ .bar = false }",
4340 .diag = null,
4341 .errors = null,
43414342 });
43424343 expected.bar = false;
43434344 try std.testing.expectEqualDeep(expected, found);
......@@ -4346,7 +4347,7 @@ test "std.zon update basic" {
43464347 .gpa = gpa,
43474348 .arena = arena,
43484349 .source = ".{ .baz = .{ .a = .{ 2, 4 } } }",
4349 .diag = null,
4350 .errors = null,
43504351 });
43514352 expected.baz.a[0] = 2;
43524353 expected.baz.a[1] = 4;
......@@ -4356,7 +4357,7 @@ test "std.zon update basic" {
43564357 .gpa = gpa,
43574358 .arena = arena,
43584359 .source = ".{ .foo = 11, .baz = .{ .b = .d } }",
4359 .diag = null,
4360 .errors = null,
43604361 });
43614362 expected.foo = 11;
43624363 expected.baz.b = .d;
......@@ -4366,7 +4367,7 @@ test "std.zon update basic" {
43664367 .gpa = gpa,
43674368 .arena = arena,
43684369 .source = ".{ .optional = 10 }",
4369 .diag = null,
4370 .errors = null,
43704371 });
43714372 expected.optional = 10;
43724373 try std.testing.expectEqualDeep(expected, found);
......@@ -4375,7 +4376,7 @@ test "std.zon update basic" {
43754376 .gpa = gpa,
43764377 .arena = arena,
43774378 .source = ".{ .optional = null }",
4378 .diag = null,
4379 .errors = null,
43794380 });
43804381 expected.optional = null;
43814382 try std.testing.expectEqualDeep(expected, found);
......@@ -4384,7 +4385,7 @@ test "std.zon update basic" {
43844385 .gpa = gpa,
43854386 .arena = arena,
43864387 .source = ".{ .ptr = .{ .x = 10, .y = 20, .z = 30 } }",
4387 .diag = null,
4388 .errors = null,
43884389 });
43894390 expected.ptr.x = 10;
43904391 expected.ptr.y = 20;
......@@ -4395,7 +4396,7 @@ test "std.zon update basic" {
43954396 .gpa = gpa,
43964397 .arena = arena,
43974398 .source = ".{ .str = \"foo\" }",
4398 .diag = null,
4399 .errors = null,
43994400 });
44004401 expected.str = "foo";
44014402 try std.testing.expectEqualDeep(expected, found);
......@@ -4418,7 +4419,7 @@ test "std.zon update optionals" {
44184419 try updateFromSlice(MyStruct, &found, .{
44194420 .gpa = gpa,
44204421 .source = ".{ .foo = .{ .qux = 3 } }",
4421 .diag = null,
4422 .errors = null,
44224423 });
44234424 expected.foo = .{ .qux = 3 };
44244425 try std.testing.expectEqual(expected, found);
......@@ -4427,13 +4428,13 @@ test "std.zon update optionals" {
44274428 // Updating an optional that starts out null should error if we leave off required fields.
44284429 {
44294430 var found: MyStruct = .{ .foo = null };
4430 var diag: Diagnostics = .init(arena);
4431 var errors: Errors = .init(arena);
44314432 try std.testing.expectError(error.ParseZon, updateFromSlice(MyStruct, &found, .{
44324433 .gpa = gpa,
44334434 .source = ".{ .foo = .{} }",
4434 .diag = &diag,
4435 .errors = &errors,
44354436 }));
4436 try std.testing.expectFmt("1:12: error: missing required field qux\n", "{f}", .{diag});
4437 try std.testing.expectFmt("1:12: error: missing required field qux\n", "{f}", .{errors});
44374438 }
44384439
44394440 // Updating an optional that starts out non-null should preserve any values we leave off. It's
......@@ -4446,7 +4447,7 @@ test "std.zon update optionals" {
44464447 try updateFromSlice(MyStruct, &found, .{
44474448 .gpa = gpa,
44484449 .source = ".{ .foo = .{ .baz = 200 } }",
4449 .diag = null,
4450 .errors = null,
44504451 });
44514452 expected.foo.?.baz = 200;
44524453 try std.testing.expectEqual(expected, found);
......@@ -4471,7 +4472,7 @@ test "std.zon update optional pointers" {
44714472 .gpa = gpa,
44724473 .arena = arena,
44734474 .source = ".{ .foo = .{ .qux = 3 } }",
4474 .diag = null,
4475 .errors = null,
44754476 });
44764477 expected.foo = &.{ .qux = 3 };
44774478 try std.testing.expectEqualDeep(expected, found);
......@@ -4496,7 +4497,7 @@ test "std.zon update pointers" {
44964497 .gpa = gpa,
44974498 .arena = arena,
44984499 .source = ".{ .foo = .{ .bar = 100 } }",
4499 .diag = null,
4500 .errors = null,
45004501 });
45014502 expected.foo.bar = 100;
45024503 try std.testing.expectEqualDeep(expected, found);
......@@ -4513,7 +4514,7 @@ test "std.zon update pointers" {
45134514 .gpa = gpa,
45144515 .arena = arena,
45154516 .source = ".{ .foo = .{ .bar = 100 } }",
4516 .diag = null,
4517 .errors = null,
45174518 });
45184519 expected.foo = &.{ .bar = 100, .baz = 20, .qux = 3 };
45194520 try std.testing.expectEqualDeep(expected, found);
......@@ -4538,7 +4539,7 @@ test "std.zon update unions" {
45384539 try updateFromSlice(MyUnion, &found, .{
45394540 .gpa = gpa,
45404541 .source = ".{ .foo = .{ .qux = 3 } }",
4541 .diag = null,
4542 .errors = null,
45424543 });
45434544 expected = .{ .foo = .{ .qux = 3 } };
45444545 try std.testing.expectEqual(expected, found);
......@@ -4547,13 +4548,13 @@ test "std.zon update unions" {
45474548 // Updating a union to a new field should error if we leave off required sub-fields
45484549 {
45494550 var found: MyUnion = .none;
4550 var diag: Diagnostics = .init(arena);
4551 var errors: Errors = .init(arena);
45514552 try std.testing.expectError(error.ParseZon, updateFromSlice(MyUnion, &found, .{
45524553 .gpa = gpa,
45534554 .source = ".{ .foo = .{} }",
4554 .diag = &diag,
4555 .errors = &errors,
45554556 }));
4556 try std.testing.expectFmt("1:12: error: missing required field qux\n", "{f}", .{diag});
4557 try std.testing.expectFmt("1:12: error: missing required field qux\n", "{f}", .{errors});
45574558 }
45584559
45594560 // Updating a union should preseve any sub-fields that we left off. It's also okay to leave off
......@@ -4566,7 +4567,7 @@ test "std.zon update unions" {
45664567 try updateFromSlice(MyUnion, &found, .{
45674568 .gpa = gpa,
45684569 .source = ".{ .foo = .{ .baz = 200 } }",
4569 .diag = null,
4570 .errors = null,
45704571 });
45714572 expected.foo.baz = 200;
45724573 try std.testing.expectEqual(expected, found);
......@@ -4597,7 +4598,7 @@ test "std.zon variants" {
45974598 try updateFromSlice(Struct, &curr, .{
45984599 .gpa = gpa,
45994600 .source = ".{ .a = 100 }",
4600 .diag = null,
4601 .errors = null,
46014602 });
46024603 try std.testing.expectEqual(end, curr);
46034604
......@@ -4606,7 +4607,7 @@ test "std.zon variants" {
46064607 .gpa = gpa,
46074608 .arena = arena,
46084609 .source = ".{ .a = 100 }",
4609 .diag = null,
4610 .errors = null,
46104611 });
46114612 try std.testing.expectEqual(end, curr);
46124613
......@@ -4614,7 +4615,7 @@ test "std.zon variants" {
46144615 try updateFromZoir(Struct, &curr, .{
46154616 .ast = &ast,
46164617 .zoir = &zoir,
4617 .diag = null,
4618 .errors = null,
46184619 });
46194620 try std.testing.expectEqual(end, curr);
46204621
......@@ -4623,7 +4624,7 @@ test "std.zon variants" {
46234624 .arena = arena,
46244625 .ast = &ast,
46254626 .zoir = &zoir,
4626 .diag = null,
4627 .errors = null,
46274628 });
46284629 try std.testing.expectEqual(end, curr);
46294630 }
......@@ -4640,7 +4641,7 @@ test "std.zon variants" {
46404641 try fromSlice(Struct, .{
46414642 .gpa = gpa,
46424643 .source = ".{ .a = 100, .b = 20 }",
4643 .diag = null,
4644 .errors = null,
46444645 }),
46454646 );
46464647 try std.testing.expectEqual(
......@@ -4649,14 +4650,14 @@ test "std.zon variants" {
46494650 .gpa = gpa,
46504651 .arena = arena,
46514652 .source = ".{ .a = 100, .b = 20 }",
4652 .diag = null,
4653 .errors = null,
46534654 }),
46544655 );
46554656 try std.testing.expectEqual(
46564657 try fromZoir(Struct, .{
46574658 .ast = &ast,
46584659 .zoir = &zoir,
4659 .diag = null,
4660 .errors = null,
46604661 }),
46614662 end,
46624663 );
......@@ -4665,7 +4666,7 @@ test "std.zon variants" {
46654666 .arena = arena,
46664667 .ast = &ast,
46674668 .zoir = &zoir,
4668 .diag = null,
4669 .errors = null,
46694670 }),
46704671 end,
46714672 );