authorgravatar for mason@anthropicstudios.comMason Remaley <mason@anthropicstudios.com> 2025-02-21 22:49:32-08:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-04-02 06:08:55+01:00
log65649576dbd3900103d3d96cdad94509f2217545
treeebe8d64a6ae88202ea9da6cd1486115e4c32e228
parent3b2fec17a4dfe034c28f528d003bf09b5e44c2b6
signaturelock-open Commit is signed but in an unrecognized format.

std.zon.parse: rename `Status` to `Diagnostics`

This name is more appropriate and in line with the rest of `std`.

1 files changed, 433 insertions(+), 433 deletions(-)

lib/std/zon/parse.zig+433-433
......@@ -44,13 +44,13 @@ pub const Error = union(enum) {
4444 pub const Iterator = struct {
4545 index: usize = 0,
4646 err: Error,
47 status: *const Status,
47 diag: *const Diagnostics,
4848
4949 pub fn next(self: *@This()) ?Note {
5050 switch (self.err) {
5151 .zoir => |err| {
5252 if (self.index >= err.note_count) return null;
53 const zoir = self.status.zoir.?;
53 const zoir = self.diag.zoir.?;
5454 const note = err.getNotes(zoir)[self.index];
5555 self.index += 1;
5656 return .{ .zoir = note };
......@@ -80,15 +80,15 @@ pub const Error = union(enum) {
8080 try writer.writeAll(self);
8181 }
8282
83 pub fn fmtMessage(self: Note, status: *const Status) std.fmt.Formatter(Note.formatMessage) {
83 pub fn fmtMessage(self: Note, diag: *const Diagnostics) std.fmt.Formatter(Note.formatMessage) {
8484 return .{ .data = switch (self) {
85 .zoir => |note| note.msg.get(status.zoir.?),
85 .zoir => |note| note.msg.get(diag.zoir.?),
8686 .type_check => |note| note.msg,
8787 } };
8888 }
8989
90 pub fn getLocation(self: Note, status: *const Status) Ast.Location {
91 const ast = status.ast.?;
90 pub fn getLocation(self: Note, diag: *const Diagnostics) Ast.Location {
91 const ast = diag.ast.?;
9292 switch (self) {
9393 .zoir => |note| return zoirErrorLocation(ast, note.token, note.node_or_offset),
9494 .type_check => |note| return ast.tokenLocation(note.offset, note.token),
......@@ -98,10 +98,10 @@ pub const Error = union(enum) {
9898
9999 pub const Iterator = struct {
100100 index: usize = 0,
101 status: *const Status,
101 diag: *const Diagnostics,
102102
103103 pub fn next(self: *@This()) ?Error {
104 const zoir = self.status.zoir orelse return null;
104 const zoir = self.diag.zoir orelse return null;
105105
106106 if (self.index < zoir.compile_errors.len) {
107107 const result: Error = .{ .zoir = zoir.compile_errors[self.index] };
......@@ -109,7 +109,7 @@ pub const Error = union(enum) {
109109 return result;
110110 }
111111
112 if (self.status.type_check) |err| {
112 if (self.diag.type_check) |err| {
113113 if (self.index == zoir.compile_errors.len) {
114114 const result: Error = .{ .type_check = err };
115115 self.index += 1;
......@@ -156,7 +156,7 @@ pub const Error = union(enum) {
156156
157157 const FormatMessage = struct {
158158 err: Error,
159 status: *const Status,
159 diag: *const Diagnostics,
160160 };
161161
162162 fn formatMessage(
......@@ -168,23 +168,23 @@ pub const Error = union(enum) {
168168 _ = f;
169169 _ = options;
170170 switch (self.err) {
171 .zoir => |err| try writer.writeAll(err.msg.get(self.status.zoir.?)),
171 .zoir => |err| try writer.writeAll(err.msg.get(self.diag.zoir.?)),
172172 .type_check => |tc| try writer.writeAll(tc.message),
173173 }
174174 }
175175
176 pub fn fmtMessage(self: @This(), status: *const Status) std.fmt.Formatter(formatMessage) {
176 pub fn fmtMessage(self: @This(), diag: *const Diagnostics) std.fmt.Formatter(formatMessage) {
177177 return .{ .data = .{
178178 .err = self,
179 .status = status,
179 .diag = diag,
180180 } };
181181 }
182182
183 pub fn getLocation(self: @This(), status: *const Status) Ast.Location {
184 const ast = status.ast.?;
183 pub fn getLocation(self: @This(), diag: *const Diagnostics) Ast.Location {
184 const ast = diag.ast.?;
185185 return switch (self) {
186186 .zoir => |err| return zoirErrorLocation(
187 status.ast.?,
187 diag.ast.?,
188188 err.token,
189189 err.node_or_offset,
190190 ),
......@@ -192,8 +192,8 @@ pub const Error = union(enum) {
192192 };
193193 }
194194
195 pub fn iterateNotes(self: @This(), status: *const Status) Note.Iterator {
196 return .{ .err = self, .status = status };
195 pub fn iterateNotes(self: @This(), diag: *const Diagnostics) Note.Iterator {
196 return .{ .err = self, .diag = diag };
197197 }
198198
199199 fn zoirErrorLocation(ast: Ast, maybe_token: Ast.OptionalTokenIndex, node_or_offset: u32) Ast.Location {
......@@ -210,26 +210,26 @@ pub const Error = union(enum) {
210210};
211211
212212/// Information about the success or failure of a parse.
213pub const Status = struct {
213pub const Diagnostics = struct {
214214 ast: ?Ast = null,
215215 zoir: ?Zoir = null,
216216 type_check: ?Error.TypeCheckFailure = null,
217217
218 fn assertEmpty(self: Status) void {
218 fn assertEmpty(self: Diagnostics) void {
219219 assert(self.ast == null);
220220 assert(self.zoir == null);
221221 assert(self.type_check == null);
222222 }
223223
224 pub fn deinit(self: *Status, gpa: Allocator) void {
224 pub fn deinit(self: *Diagnostics, gpa: Allocator) void {
225225 if (self.ast) |*ast| ast.deinit(gpa);
226226 if (self.zoir) |*zoir| zoir.deinit(gpa);
227227 if (self.type_check) |tc| tc.deinit(gpa);
228228 self.* = undefined;
229229 }
230230
231 pub fn iterateErrors(self: *const Status) Error.Iterator {
232 return .{ .status = self };
231 pub fn iterateErrors(self: *const Diagnostics) Error.Iterator {
232 return .{ .diag = self };
233233 }
234234
235235 pub fn format(
......@@ -266,7 +266,7 @@ pub const Status = struct {
266266/// invalid or can not be deserialized into type `T`.
267267///
268268/// When the parser returns `error.ParseZon`, it will also store a human readable explanation in
269/// `status` if non null. If status is not null, it must be initialized to `.{}`.
269/// `diag` if non null. If diag is not null, it must be initialized to `.{}`.
270270pub fn fromSlice(
271271 /// The type to deserialize into. May not be or contain any of the following types:
272272 /// * Any comptime-only type, except in a comptime field
......@@ -283,22 +283,22 @@ pub fn fromSlice(
283283 T: type,
284284 gpa: Allocator,
285285 source: [:0]const u8,
286 status: ?*Status,
286 diag: ?*Diagnostics,
287287 options: Options,
288288) error{ OutOfMemory, ParseZon }!T {
289 if (status) |s| s.assertEmpty();
289 if (diag) |s| s.assertEmpty();
290290
291291 var ast = try std.zig.Ast.parse(gpa, source, .zon);
292 defer if (status == null) ast.deinit(gpa);
293 if (status) |s| s.ast = ast;
292 defer if (diag == null) ast.deinit(gpa);
293 if (diag) |s| s.ast = ast;
294294
295 // If there's no status, Zoir exists for the lifetime of this function. If there is a status,
296 // ownership is transferred to status.
295 // If there's no diagnostics, Zoir exists for the lifetime of this function. If there is a
296 // diagnostics, ownership is transferred to diagnostics.
297297 var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false });
298 defer if (status == null) zoir.deinit(gpa);
298 defer if (diag == null) zoir.deinit(gpa);
299299
300 if (status) |s| s.* = .{};
301 return fromZoir(T, gpa, ast, zoir, status, options);
300 if (diag) |s| s.* = .{};
301 return fromZoir(T, gpa, ast, zoir, diag, options);
302302}
303303
304304/// Like `fromSlice`, but operates on `Zoir` instead of ZON source.
......@@ -307,10 +307,10 @@ pub fn fromZoir(
307307 gpa: Allocator,
308308 ast: Ast,
309309 zoir: Zoir,
310 status: ?*Status,
310 diag: ?*Diagnostics,
311311 options: Options,
312312) error{ OutOfMemory, ParseZon }!T {
313 return fromZoirNode(T, gpa, ast, zoir, .root, status, options);
313 return fromZoirNode(T, gpa, ast, zoir, .root, diag, options);
314314}
315315
316316/// Like `fromZoir`, but the parse starts on `node` instead of root.
......@@ -320,12 +320,12 @@ pub fn fromZoirNode(
320320 ast: Ast,
321321 zoir: Zoir,
322322 node: Zoir.Node.Index,
323 status: ?*Status,
323 diag: ?*Diagnostics,
324324 options: Options,
325325) error{ OutOfMemory, ParseZon }!T {
326326 comptime assert(canParseType(T));
327327
328 if (status) |s| {
328 if (diag) |s| {
329329 s.assertEmpty();
330330 s.ast = ast;
331331 s.zoir = zoir;
......@@ -340,7 +340,7 @@ pub fn fromZoirNode(
340340 .ast = ast,
341341 .zoir = zoir,
342342 .options = options,
343 .status = status,
343 .diag = diag,
344344 };
345345
346346 return parser.parseExpr(T, node);
......@@ -421,7 +421,7 @@ const Parser = struct {
421421 gpa: Allocator,
422422 ast: Ast,
423423 zoir: Zoir,
424 status: ?*Status,
424 diag: ?*Diagnostics,
425425 options: Options,
426426
427427 fn parseExpr(self: *@This(), T: type, node: Zoir.Node.Index) error{ ParseZon, OutOfMemory }!T {
......@@ -988,7 +988,7 @@ const Parser = struct {
988988 ) error{ OutOfMemory, ParseZon } {
989989 @branchHint(.cold);
990990 comptime assert(args.len > 0);
991 if (self.status) |s| s.type_check = .{
991 if (self.diag) |s| s.type_check = .{
992992 .token = token,
993993 .offset = offset,
994994 .message = std.fmt.allocPrint(self.gpa, fmt, args) catch |err| {
......@@ -1017,7 +1017,7 @@ const Parser = struct {
10171017 failure: Error.TypeCheckFailure,
10181018 ) error{ParseZon} {
10191019 @branchHint(.cold);
1020 if (self.status) |s| s.type_check = failure;
1020 if (self.diag) |s| s.type_check = failure;
10211021 return error.ParseZon;
10221022 }
10231023
......@@ -1283,13 +1283,13 @@ test "std.zon requiresAllocator" {
12831283
12841284test "std.zon ast errors" {
12851285 const gpa = std.testing.allocator;
1286 var status: Status = .{};
1287 defer status.deinit(gpa);
1286 var diag: Diagnostics = .{};
1287 defer diag.deinit(gpa);
12881288 try std.testing.expectError(
12891289 error.ParseZon,
1290 fromSlice(struct {}, gpa, ".{.x = 1 .y = 2}", &status, .{}),
1290 fromSlice(struct {}, gpa, ".{.x = 1 .y = 2}", &diag, .{}),
12911291 );
1292 try std.testing.expectFmt("1:13: error: expected ',' after initializer\n", "{}", .{status});
1292 try std.testing.expectFmt("1:13: error: expected ',' after initializer\n", "{}", .{diag});
12931293}
12941294
12951295test "std.zon comments" {
......@@ -1302,17 +1302,17 @@ test "std.zon comments" {
13021302 , null, .{}));
13031303
13041304 {
1305 var status: Status = .{};
1306 defer status.deinit(gpa);
1305 var diag: Diagnostics = .{};
1306 defer diag.deinit(gpa);
13071307 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa,
13081308 \\//! comment
13091309 \\10 // comment
13101310 \\// comment
1311 , &status, .{}));
1311 , &diag, .{}));
13121312 try std.testing.expectFmt(
13131313 "1:1: error: expected expression, found 'a document comment'\n",
13141314 "{}",
1315 .{status},
1315 .{diag},
13161316 );
13171317 }
13181318}
......@@ -1323,16 +1323,16 @@ test "std.zon failure/oom formatting" {
13231323 .fail_index = 0,
13241324 .resize_fail_index = 0,
13251325 });
1326 var status: Status = .{};
1327 defer status.deinit(gpa);
1326 var diag: Diagnostics = .{};
1327 defer diag.deinit(gpa);
13281328 try std.testing.expectError(error.OutOfMemory, fromSlice(
13291329 []const u8,
13301330 failing_allocator.allocator(),
13311331 "\"foo\"",
1332 &status,
1332 &diag,
13331333 .{},
13341334 ));
1335 try std.testing.expectFmt("", "{}", .{status});
1335 try std.testing.expectFmt("", "{}", .{diag});
13361336}
13371337
13381338test "std.zon fromSlice syntax error" {
......@@ -1401,11 +1401,11 @@ test "std.zon unions" {
14011401 // Unknown field
14021402 {
14031403 const Union = union { x: f32, y: f32 };
1404 var status: Status = .{};
1405 defer status.deinit(gpa);
1404 var diag: Diagnostics = .{};
1405 defer diag.deinit(gpa);
14061406 try std.testing.expectError(
14071407 error.ParseZon,
1408 fromSlice(Union, gpa, ".{.z=2.5}", &status, .{}),
1408 fromSlice(Union, gpa, ".{.z=2.5}", &diag, .{}),
14091409 );
14101410 try std.testing.expectFmt(
14111411 \\1:4: error: unexpected field 'z'
......@@ -1413,78 +1413,78 @@ test "std.zon unions" {
14131413 \\
14141414 ,
14151415 "{}",
1416 .{status},
1416 .{diag},
14171417 );
14181418 }
14191419
14201420 // Explicit void field
14211421 {
14221422 const Union = union(enum) { x: void };
1423 var status: Status = .{};
1424 defer status.deinit(gpa);
1423 var diag: Diagnostics = .{};
1424 defer diag.deinit(gpa);
14251425 try std.testing.expectError(
14261426 error.ParseZon,
1427 fromSlice(Union, gpa, ".{.x=1}", &status, .{}),
1427 fromSlice(Union, gpa, ".{.x=1}", &diag, .{}),
14281428 );
1429 try std.testing.expectFmt("1:6: error: expected type 'void'\n", "{}", .{status});
1429 try std.testing.expectFmt("1:6: error: expected type 'void'\n", "{}", .{diag});
14301430 }
14311431
14321432 // Extra field
14331433 {
14341434 const Union = union { x: f32, y: bool };
1435 var status: Status = .{};
1436 defer status.deinit(gpa);
1435 var diag: Diagnostics = .{};
1436 defer diag.deinit(gpa);
14371437 try std.testing.expectError(
14381438 error.ParseZon,
1439 fromSlice(Union, gpa, ".{.x = 1.5, .y = true}", &status, .{}),
1439 fromSlice(Union, gpa, ".{.x = 1.5, .y = true}", &diag, .{}),
14401440 );
1441 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status});
1441 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag});
14421442 }
14431443
14441444 // No fields
14451445 {
14461446 const Union = union { x: f32, y: bool };
1447 var status: Status = .{};
1448 defer status.deinit(gpa);
1447 var diag: Diagnostics = .{};
1448 defer diag.deinit(gpa);
14491449 try std.testing.expectError(
14501450 error.ParseZon,
1451 fromSlice(Union, gpa, ".{}", &status, .{}),
1451 fromSlice(Union, gpa, ".{}", &diag, .{}),
14521452 );
1453 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status});
1453 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag});
14541454 }
14551455
14561456 // Enum literals cannot coerce into untagged unions
14571457 {
14581458 const Union = union { x: void };
1459 var status: Status = .{};
1460 defer status.deinit(gpa);
1461 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &status, .{}));
1462 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status});
1459 var diag: Diagnostics = .{};
1460 defer diag.deinit(gpa);
1461 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &diag, .{}));
1462 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag});
14631463 }
14641464
14651465 // Unknown field for enum literal coercion
14661466 {
14671467 const Union = union(enum) { x: void };
1468 var status: Status = .{};
1469 defer status.deinit(gpa);
1470 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".y", &status, .{}));
1468 var diag: Diagnostics = .{};
1469 defer diag.deinit(gpa);
1470 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".y", &diag, .{}));
14711471 try std.testing.expectFmt(
14721472 \\1:2: error: unexpected field 'y'
14731473 \\1:2: note: supported: 'x'
14741474 \\
14751475 ,
14761476 "{}",
1477 .{status},
1477 .{diag},
14781478 );
14791479 }
14801480
14811481 // Non void field for enum literal coercion
14821482 {
14831483 const Union = union(enum) { x: f32 };
1484 var status: Status = .{};
1485 defer status.deinit(gpa);
1486 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &status, .{}));
1487 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status});
1484 var diag: Diagnostics = .{};
1485 defer diag.deinit(gpa);
1486 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &diag, .{}));
1487 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag});
14881488 }
14891489}
14901490
......@@ -1529,11 +1529,11 @@ test "std.zon structs" {
15291529 // Unknown field
15301530 {
15311531 const Vec2 = struct { x: f32, y: f32 };
1532 var status: Status = .{};
1533 defer status.deinit(gpa);
1532 var diag: Diagnostics = .{};
1533 defer diag.deinit(gpa);
15341534 try std.testing.expectError(
15351535 error.ParseZon,
1536 fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &status, .{}),
1536 fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &diag, .{}),
15371537 );
15381538 try std.testing.expectFmt(
15391539 \\1:12: error: unexpected field 'z'
......@@ -1541,24 +1541,24 @@ test "std.zon structs" {
15411541 \\
15421542 ,
15431543 "{}",
1544 .{status},
1544 .{diag},
15451545 );
15461546 }
15471547
15481548 // Duplicate field
15491549 {
15501550 const Vec2 = struct { x: f32, y: f32 };
1551 var status: Status = .{};
1552 defer status.deinit(gpa);
1551 var diag: Diagnostics = .{};
1552 defer diag.deinit(gpa);
15531553 try std.testing.expectError(
15541554 error.ParseZon,
1555 fromSlice(Vec2, gpa, ".{.x=1.5, .x=2.5, .x=3.5}", &status, .{}),
1555 fromSlice(Vec2, gpa, ".{.x=1.5, .x=2.5, .x=3.5}", &diag, .{}),
15561556 );
15571557 try std.testing.expectFmt(
15581558 \\1:4: error: duplicate struct field name
15591559 \\1:12: note: duplicate name here
15601560 \\
1561 , "{}", .{status});
1561 , "{}", .{diag});
15621562 }
15631563
15641564 // Ignore unknown fields
......@@ -1573,29 +1573,29 @@ test "std.zon structs" {
15731573 // Unknown field when struct has no fields (regression test)
15741574 {
15751575 const Vec2 = struct {};
1576 var status: Status = .{};
1577 defer status.deinit(gpa);
1576 var diag: Diagnostics = .{};
1577 defer diag.deinit(gpa);
15781578 try std.testing.expectError(
15791579 error.ParseZon,
1580 fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &status, .{}),
1580 fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &diag, .{}),
15811581 );
15821582 try std.testing.expectFmt(
15831583 \\1:4: error: unexpected field 'x'
15841584 \\1:4: note: none expected
15851585 \\
1586 , "{}", .{status});
1586 , "{}", .{diag});
15871587 }
15881588
15891589 // Missing field
15901590 {
15911591 const Vec2 = struct { x: f32, y: f32 };
1592 var status: Status = .{};
1593 defer status.deinit(gpa);
1592 var diag: Diagnostics = .{};
1593 defer diag.deinit(gpa);
15941594 try std.testing.expectError(
15951595 error.ParseZon,
1596 fromSlice(Vec2, gpa, ".{.x=1.5}", &status, .{}),
1596 fromSlice(Vec2, gpa, ".{.x=1.5}", &diag, .{}),
15971597 );
1598 try std.testing.expectFmt("1:2: error: missing required field y\n", "{}", .{status});
1598 try std.testing.expectFmt("1:2: error: missing required field y\n", "{}", .{diag});
15991599 }
16001600
16011601 // Default field
......@@ -1615,14 +1615,14 @@ test "std.zon structs" {
16151615 // Comptime field assignment
16161616 {
16171617 const Vec2 = struct { x: f32, comptime y: f32 = 1.5 };
1618 var status: Status = .{};
1619 defer status.deinit(gpa);
1620 const parsed = fromSlice(Vec2, gpa, ".{.x = 1.2, .y = 1.5}", &status, .{});
1618 var diag: Diagnostics = .{};
1619 defer diag.deinit(gpa);
1620 const parsed = fromSlice(Vec2, gpa, ".{.x = 1.2, .y = 1.5}", &diag, .{});
16211621 try std.testing.expectError(error.ParseZon, parsed);
16221622 try std.testing.expectFmt(
16231623 \\1:18: error: cannot initialize comptime field
16241624 \\
1625 , "{}", .{status});
1625 , "{}", .{diag});
16261626 }
16271627
16281628 // Enum field (regression test, we were previously getting the field name in an
......@@ -1644,52 +1644,52 @@ test "std.zon structs" {
16441644 {
16451645 // Structs
16461646 {
1647 var status: Status = .{};
1648 defer status.deinit(gpa);
1649 const parsed = fromSlice(struct {}, gpa, "Empty{}", &status, .{});
1647 var diag: Diagnostics = .{};
1648 defer diag.deinit(gpa);
1649 const parsed = fromSlice(struct {}, gpa, "Empty{}", &diag, .{});
16501650 try std.testing.expectError(error.ParseZon, parsed);
16511651 try std.testing.expectFmt(
16521652 \\1:1: error: types are not available in ZON
16531653 \\1:1: note: replace the type with '.'
16541654 \\
1655 , "{}", .{status});
1655 , "{}", .{diag});
16561656 }
16571657
16581658 // Arrays
16591659 {
1660 var status: Status = .{};
1661 defer status.deinit(gpa);
1662 const parsed = fromSlice([3]u8, gpa, "[3]u8{1, 2, 3}", &status, .{});
1660 var diag: Diagnostics = .{};
1661 defer diag.deinit(gpa);
1662 const parsed = fromSlice([3]u8, gpa, "[3]u8{1, 2, 3}", &diag, .{});
16631663 try std.testing.expectError(error.ParseZon, parsed);
16641664 try std.testing.expectFmt(
16651665 \\1:1: error: types are not available in ZON
16661666 \\1:1: note: replace the type with '.'
16671667 \\
1668 , "{}", .{status});
1668 , "{}", .{diag});
16691669 }
16701670
16711671 // Slices
16721672 {
1673 var status: Status = .{};
1674 defer status.deinit(gpa);
1675 const parsed = fromSlice([]u8, gpa, "[]u8{1, 2, 3}", &status, .{});
1673 var diag: Diagnostics = .{};
1674 defer diag.deinit(gpa);
1675 const parsed = fromSlice([]u8, gpa, "[]u8{1, 2, 3}", &diag, .{});
16761676 try std.testing.expectError(error.ParseZon, parsed);
16771677 try std.testing.expectFmt(
16781678 \\1:1: error: types are not available in ZON
16791679 \\1:1: note: replace the type with '.'
16801680 \\
1681 , "{}", .{status});
1681 , "{}", .{diag});
16821682 }
16831683
16841684 // Tuples
16851685 {
1686 var status: Status = .{};
1687 defer status.deinit(gpa);
1686 var diag: Diagnostics = .{};
1687 defer diag.deinit(gpa);
16881688 const parsed = fromSlice(
16891689 struct { u8, u8, u8 },
16901690 gpa,
16911691 "Tuple{1, 2, 3}",
1692 &status,
1692 &diag,
16931693 .{},
16941694 );
16951695 try std.testing.expectError(error.ParseZon, parsed);
......@@ -1697,20 +1697,20 @@ test "std.zon structs" {
16971697 \\1:1: error: types are not available in ZON
16981698 \\1:1: note: replace the type with '.'
16991699 \\
1700 , "{}", .{status});
1700 , "{}", .{diag});
17011701 }
17021702
17031703 // Nested
17041704 {
1705 var status: Status = .{};
1706 defer status.deinit(gpa);
1707 const parsed = fromSlice(struct {}, gpa, ".{ .x = Tuple{1, 2, 3} }", &status, .{});
1705 var diag: Diagnostics = .{};
1706 defer diag.deinit(gpa);
1707 const parsed = fromSlice(struct {}, gpa, ".{ .x = Tuple{1, 2, 3} }", &diag, .{});
17081708 try std.testing.expectError(error.ParseZon, parsed);
17091709 try std.testing.expectFmt(
17101710 \\1:9: error: types are not available in ZON
17111711 \\1:9: note: replace the type with '.'
17121712 \\
1713 , "{}", .{status});
1713 , "{}", .{diag});
17141714 }
17151715 }
17161716}
......@@ -1749,53 +1749,53 @@ test "std.zon tuples" {
17491749 // Extra field
17501750 {
17511751 const Tuple = struct { f32, bool };
1752 var status: Status = .{};
1753 defer status.deinit(gpa);
1752 var diag: Diagnostics = .{};
1753 defer diag.deinit(gpa);
17541754 try std.testing.expectError(
17551755 error.ParseZon,
1756 fromSlice(Tuple, gpa, ".{0.5, true, 123}", &status, .{}),
1756 fromSlice(Tuple, gpa, ".{0.5, true, 123}", &diag, .{}),
17571757 );
1758 try std.testing.expectFmt("1:14: error: index 2 outside of tuple length 2\n", "{}", .{status});
1758 try std.testing.expectFmt("1:14: error: index 2 outside of tuple length 2\n", "{}", .{diag});
17591759 }
17601760
17611761 // Extra field
17621762 {
17631763 const Tuple = struct { f32, bool };
1764 var status: Status = .{};
1765 defer status.deinit(gpa);
1764 var diag: Diagnostics = .{};
1765 defer diag.deinit(gpa);
17661766 try std.testing.expectError(
17671767 error.ParseZon,
1768 fromSlice(Tuple, gpa, ".{0.5}", &status, .{}),
1768 fromSlice(Tuple, gpa, ".{0.5}", &diag, .{}),
17691769 );
17701770 try std.testing.expectFmt(
17711771 "1:2: error: missing tuple field with index 1\n",
17721772 "{}",
1773 .{status},
1773 .{diag},
17741774 );
17751775 }
17761776
17771777 // Tuple with unexpected field names
17781778 {
17791779 const Tuple = struct { f32 };
1780 var status: Status = .{};
1781 defer status.deinit(gpa);
1780 var diag: Diagnostics = .{};
1781 defer diag.deinit(gpa);
17821782 try std.testing.expectError(
17831783 error.ParseZon,
1784 fromSlice(Tuple, gpa, ".{.foo = 10.0}", &status, .{}),
1784 fromSlice(Tuple, gpa, ".{.foo = 10.0}", &diag, .{}),
17851785 );
1786 try std.testing.expectFmt("1:2: error: expected tuple\n", "{}", .{status});
1786 try std.testing.expectFmt("1:2: error: expected tuple\n", "{}", .{diag});
17871787 }
17881788
17891789 // Struct with missing field names
17901790 {
17911791 const Struct = struct { foo: f32 };
1792 var status: Status = .{};
1793 defer status.deinit(gpa);
1792 var diag: Diagnostics = .{};
1793 defer diag.deinit(gpa);
17941794 try std.testing.expectError(
17951795 error.ParseZon,
1796 fromSlice(Struct, gpa, ".{10.0}", &status, .{}),
1796 fromSlice(Struct, gpa, ".{10.0}", &diag, .{}),
17971797 );
1798 try std.testing.expectFmt("1:2: error: expected struct\n", "{}", .{status});
1798 try std.testing.expectFmt("1:2: error: expected struct\n", "{}", .{diag});
17991799 }
18001800
18011801 // Comptime field
......@@ -1808,14 +1808,14 @@ test "std.zon tuples" {
18081808 // Comptime field assignment
18091809 {
18101810 const Vec2 = struct { f32, comptime f32 = 1.5 };
1811 var status: Status = .{};
1812 defer status.deinit(gpa);
1813 const parsed = fromSlice(Vec2, gpa, ".{ 1.2, 1.5}", &status, .{});
1811 var diag: Diagnostics = .{};
1812 defer diag.deinit(gpa);
1813 const parsed = fromSlice(Vec2, gpa, ".{ 1.2, 1.5}", &diag, .{});
18141814 try std.testing.expectError(error.ParseZon, parsed);
18151815 try std.testing.expectFmt(
18161816 \\1:9: error: cannot initialize comptime field
18171817 \\
1818 , "{}", .{status});
1818 , "{}", .{diag});
18191819 }
18201820}
18211821
......@@ -1919,61 +1919,61 @@ test "std.zon arrays and slices" {
19191919
19201920 // Expect 0 find 3
19211921 {
1922 var status: Status = .{};
1923 defer status.deinit(gpa);
1922 var diag: Diagnostics = .{};
1923 defer diag.deinit(gpa);
19241924 try std.testing.expectError(
19251925 error.ParseZon,
1926 fromSlice([0]u8, gpa, ".{'a', 'b', 'c'}", &status, .{}),
1926 fromSlice([0]u8, gpa, ".{'a', 'b', 'c'}", &diag, .{}),
19271927 );
19281928 try std.testing.expectFmt(
19291929 "1:3: error: index 0 outside of array of length 0\n",
19301930 "{}",
1931 .{status},
1931 .{diag},
19321932 );
19331933 }
19341934
19351935 // Expect 1 find 2
19361936 {
1937 var status: Status = .{};
1938 defer status.deinit(gpa);
1937 var diag: Diagnostics = .{};
1938 defer diag.deinit(gpa);
19391939 try std.testing.expectError(
19401940 error.ParseZon,
1941 fromSlice([1]u8, gpa, ".{'a', 'b'}", &status, .{}),
1941 fromSlice([1]u8, gpa, ".{'a', 'b'}", &diag, .{}),
19421942 );
19431943 try std.testing.expectFmt(
19441944 "1:8: error: index 1 outside of array of length 1\n",
19451945 "{}",
1946 .{status},
1946 .{diag},
19471947 );
19481948 }
19491949
19501950 // Expect 2 find 1
19511951 {
1952 var status: Status = .{};
1953 defer status.deinit(gpa);
1952 var diag: Diagnostics = .{};
1953 defer diag.deinit(gpa);
19541954 try std.testing.expectError(
19551955 error.ParseZon,
1956 fromSlice([2]u8, gpa, ".{'a'}", &status, .{}),
1956 fromSlice([2]u8, gpa, ".{'a'}", &diag, .{}),
19571957 );
19581958 try std.testing.expectFmt(
19591959 "1:2: error: expected 2 array elements; found 1\n",
19601960 "{}",
1961 .{status},
1961 .{diag},
19621962 );
19631963 }
19641964
19651965 // Expect 3 find 0
19661966 {
1967 var status: Status = .{};
1968 defer status.deinit(gpa);
1967 var diag: Diagnostics = .{};
1968 defer diag.deinit(gpa);
19691969 try std.testing.expectError(
19701970 error.ParseZon,
1971 fromSlice([3]u8, gpa, ".{}", &status, .{}),
1971 fromSlice([3]u8, gpa, ".{}", &diag, .{}),
19721972 );
19731973 try std.testing.expectFmt(
19741974 "1:2: error: expected 3 array elements; found 0\n",
19751975 "{}",
1976 .{status},
1976 .{diag},
19771977 );
19781978 }
19791979
......@@ -1981,24 +1981,24 @@ test "std.zon arrays and slices" {
19811981 {
19821982 // Array
19831983 {
1984 var status: Status = .{};
1985 defer status.deinit(gpa);
1984 var diag: Diagnostics = .{};
1985 defer diag.deinit(gpa);
19861986 try std.testing.expectError(
19871987 error.ParseZon,
1988 fromSlice([3]bool, gpa, ".{'a', 'b', 'c'}", &status, .{}),
1988 fromSlice([3]bool, gpa, ".{'a', 'b', 'c'}", &diag, .{}),
19891989 );
1990 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{}", .{status});
1990 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{}", .{diag});
19911991 }
19921992
19931993 // Slice
19941994 {
1995 var status: Status = .{};
1996 defer status.deinit(gpa);
1995 var diag: Diagnostics = .{};
1996 defer diag.deinit(gpa);
19971997 try std.testing.expectError(
19981998 error.ParseZon,
1999 fromSlice([]bool, gpa, ".{'a', 'b', 'c'}", &status, .{}),
1999 fromSlice([]bool, gpa, ".{'a', 'b', 'c'}", &diag, .{}),
20002000 );
2001 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{}", .{status});
2001 try std.testing.expectFmt("1:3: error: expected type 'bool'\n", "{}", .{diag});
20022002 }
20032003 }
20042004
......@@ -2006,39 +2006,39 @@ test "std.zon arrays and slices" {
20062006 {
20072007 // Array
20082008 {
2009 var status: Status = .{};
2010 defer status.deinit(gpa);
2009 var diag: Diagnostics = .{};
2010 defer diag.deinit(gpa);
20112011 try std.testing.expectError(
20122012 error.ParseZon,
2013 fromSlice([3]u8, gpa, "'a'", &status, .{}),
2013 fromSlice([3]u8, gpa, "'a'", &diag, .{}),
20142014 );
2015 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2015 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
20162016 }
20172017
20182018 // Slice
20192019 {
2020 var status: Status = .{};
2021 defer status.deinit(gpa);
2020 var diag: Diagnostics = .{};
2021 defer diag.deinit(gpa);
20222022 try std.testing.expectError(
20232023 error.ParseZon,
2024 fromSlice([]u8, gpa, "'a'", &status, .{}),
2024 fromSlice([]u8, gpa, "'a'", &diag, .{}),
20252025 );
2026 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2026 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
20272027 }
20282028 }
20292029
20302030 // Address of is not allowed (indirection for slices in ZON is implicit)
20312031 {
2032 var status: Status = .{};
2033 defer status.deinit(gpa);
2032 var diag: Diagnostics = .{};
2033 defer diag.deinit(gpa);
20342034 try std.testing.expectError(
20352035 error.ParseZon,
2036 fromSlice([]u8, gpa, " &.{'a', 'b', 'c'}", &status, .{}),
2036 fromSlice([]u8, gpa, " &.{'a', 'b', 'c'}", &diag, .{}),
20372037 );
20382038 try std.testing.expectFmt(
20392039 "1:3: error: pointers are not available in ZON\n",
20402040 "{}",
2041 .{status},
2041 .{diag},
20422042 );
20432043 }
20442044}
......@@ -2070,23 +2070,23 @@ test "std.zon string literal" {
20702070 // Passing string literal to a mutable slice
20712071 {
20722072 {
2073 var status: Status = .{};
2074 defer status.deinit(gpa);
2073 var diag: Diagnostics = .{};
2074 defer diag.deinit(gpa);
20752075 try std.testing.expectError(
20762076 error.ParseZon,
2077 fromSlice([]u8, gpa, "\"abcd\"", &status, .{}),
2077 fromSlice([]u8, gpa, "\"abcd\"", &diag, .{}),
20782078 );
2079 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2079 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
20802080 }
20812081
20822082 {
2083 var status: Status = .{};
2084 defer status.deinit(gpa);
2083 var diag: Diagnostics = .{};
2084 defer diag.deinit(gpa);
20852085 try std.testing.expectError(
20862086 error.ParseZon,
2087 fromSlice([]u8, gpa, "\\\\abcd", &status, .{}),
2087 fromSlice([]u8, gpa, "\\\\abcd", &diag, .{}),
20882088 );
2089 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2089 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
20902090 }
20912091 }
20922092
......@@ -2097,23 +2097,23 @@ test "std.zon string literal" {
20972097 defer ast.deinit(gpa);
20982098 var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false });
20992099 defer zoir.deinit(gpa);
2100 var status: Status = .{};
2101 defer status.deinit(gpa);
2100 var diag: Diagnostics = .{};
2101 defer diag.deinit(gpa);
21022102 try std.testing.expectError(
21032103 error.ParseZon,
2104 fromSlice([4:0]u8, gpa, "\"abcd\"", &status, .{}),
2104 fromSlice([4:0]u8, gpa, "\"abcd\"", &diag, .{}),
21052105 );
2106 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2106 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
21072107 }
21082108
21092109 {
2110 var status: Status = .{};
2111 defer status.deinit(gpa);
2110 var diag: Diagnostics = .{};
2111 defer diag.deinit(gpa);
21122112 try std.testing.expectError(
21132113 error.ParseZon,
2114 fromSlice([4:0]u8, gpa, "\\\\abcd", &status, .{}),
2114 fromSlice([4:0]u8, gpa, "\\\\abcd", &diag, .{}),
21152115 );
2116 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2116 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
21172117 }
21182118 }
21192119
......@@ -2149,102 +2149,102 @@ test "std.zon string literal" {
21492149 // Other value terminated slices
21502150 {
21512151 {
2152 var status: Status = .{};
2153 defer status.deinit(gpa);
2152 var diag: Diagnostics = .{};
2153 defer diag.deinit(gpa);
21542154 try std.testing.expectError(
21552155 error.ParseZon,
2156 fromSlice([:1]const u8, gpa, "\"foo\"", &status, .{}),
2156 fromSlice([:1]const u8, gpa, "\"foo\"", &diag, .{}),
21572157 );
2158 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2158 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
21592159 }
21602160
21612161 {
2162 var status: Status = .{};
2163 defer status.deinit(gpa);
2162 var diag: Diagnostics = .{};
2163 defer diag.deinit(gpa);
21642164 try std.testing.expectError(
21652165 error.ParseZon,
2166 fromSlice([:1]const u8, gpa, "\\\\foo", &status, .{}),
2166 fromSlice([:1]const u8, gpa, "\\\\foo", &diag, .{}),
21672167 );
2168 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2168 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
21692169 }
21702170 }
21712171
21722172 // Expecting string literal, getting something else
21732173 {
2174 var status: Status = .{};
2175 defer status.deinit(gpa);
2174 var diag: Diagnostics = .{};
2175 defer diag.deinit(gpa);
21762176 try std.testing.expectError(
21772177 error.ParseZon,
2178 fromSlice([]const u8, gpa, "true", &status, .{}),
2178 fromSlice([]const u8, gpa, "true", &diag, .{}),
21792179 );
2180 try std.testing.expectFmt("1:1: error: expected string\n", "{}", .{status});
2180 try std.testing.expectFmt("1:1: error: expected string\n", "{}", .{diag});
21812181 }
21822182
21832183 // Expecting string literal, getting an incompatible tuple
21842184 {
2185 var status: Status = .{};
2186 defer status.deinit(gpa);
2185 var diag: Diagnostics = .{};
2186 defer diag.deinit(gpa);
21872187 try std.testing.expectError(
21882188 error.ParseZon,
2189 fromSlice([]const u8, gpa, ".{false}", &status, .{}),
2189 fromSlice([]const u8, gpa, ".{false}", &diag, .{}),
21902190 );
2191 try std.testing.expectFmt("1:3: error: expected type 'u8'\n", "{}", .{status});
2191 try std.testing.expectFmt("1:3: error: expected type 'u8'\n", "{}", .{diag});
21922192 }
21932193
21942194 // Invalid string literal
21952195 {
2196 var status: Status = .{};
2197 defer status.deinit(gpa);
2196 var diag: Diagnostics = .{};
2197 defer diag.deinit(gpa);
21982198 try std.testing.expectError(
21992199 error.ParseZon,
2200 fromSlice([]const i8, gpa, "\"\\a\"", &status, .{}),
2200 fromSlice([]const i8, gpa, "\"\\a\"", &diag, .{}),
22012201 );
2202 try std.testing.expectFmt("1:3: error: invalid escape character: 'a'\n", "{}", .{status});
2202 try std.testing.expectFmt("1:3: error: invalid escape character: 'a'\n", "{}", .{diag});
22032203 }
22042204
22052205 // Slice wrong child type
22062206 {
22072207 {
2208 var status: Status = .{};
2209 defer status.deinit(gpa);
2208 var diag: Diagnostics = .{};
2209 defer diag.deinit(gpa);
22102210 try std.testing.expectError(
22112211 error.ParseZon,
2212 fromSlice([]const i8, gpa, "\"a\"", &status, .{}),
2212 fromSlice([]const i8, gpa, "\"a\"", &diag, .{}),
22132213 );
2214 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2214 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
22152215 }
22162216
22172217 {
2218 var status: Status = .{};
2219 defer status.deinit(gpa);
2218 var diag: Diagnostics = .{};
2219 defer diag.deinit(gpa);
22202220 try std.testing.expectError(
22212221 error.ParseZon,
2222 fromSlice([]const i8, gpa, "\\\\a", &status, .{}),
2222 fromSlice([]const i8, gpa, "\\\\a", &diag, .{}),
22232223 );
2224 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2224 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
22252225 }
22262226 }
22272227
22282228 // Bad alignment
22292229 {
22302230 {
2231 var status: Status = .{};
2232 defer status.deinit(gpa);
2231 var diag: Diagnostics = .{};
2232 defer diag.deinit(gpa);
22332233 try std.testing.expectError(
22342234 error.ParseZon,
2235 fromSlice([]align(2) const u8, gpa, "\"abc\"", &status, .{}),
2235 fromSlice([]align(2) const u8, gpa, "\"abc\"", &diag, .{}),
22362236 );
2237 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2237 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
22382238 }
22392239
22402240 {
2241 var status: Status = .{};
2242 defer status.deinit(gpa);
2241 var diag: Diagnostics = .{};
2242 defer diag.deinit(gpa);
22432243 try std.testing.expectError(
22442244 error.ParseZon,
2245 fromSlice([]align(2) const u8, gpa, "\\\\abc", &status, .{}),
2245 fromSlice([]align(2) const u8, gpa, "\\\\abc", &diag, .{}),
22462246 );
2247 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});
2247 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
22482248 }
22492249 }
22502250
......@@ -2307,11 +2307,11 @@ test "std.zon enum literals" {
23072307
23082308 // Bad tag
23092309 {
2310 var status: Status = .{};
2311 defer status.deinit(gpa);
2310 var diag: Diagnostics = .{};
2311 defer diag.deinit(gpa);
23122312 try std.testing.expectError(
23132313 error.ParseZon,
2314 fromSlice(Enum, gpa, ".qux", &status, .{}),
2314 fromSlice(Enum, gpa, ".qux", &diag, .{}),
23152315 );
23162316 try std.testing.expectFmt(
23172317 \\1:2: error: unexpected enum literal 'qux'
......@@ -2319,17 +2319,17 @@ test "std.zon enum literals" {
23192319 \\
23202320 ,
23212321 "{}",
2322 .{status},
2322 .{diag},
23232323 );
23242324 }
23252325
23262326 // Bad tag that's too long for parser
23272327 {
2328 var status: Status = .{};
2329 defer status.deinit(gpa);
2328 var diag: Diagnostics = .{};
2329 defer diag.deinit(gpa);
23302330 try std.testing.expectError(
23312331 error.ParseZon,
2332 fromSlice(Enum, gpa, ".@\"foobarbaz\"", &status, .{}),
2332 fromSlice(Enum, gpa, ".@\"foobarbaz\"", &diag, .{}),
23332333 );
23342334 try std.testing.expectFmt(
23352335 \\1:2: error: unexpected enum literal 'foobarbaz'
......@@ -2337,33 +2337,33 @@ test "std.zon enum literals" {
23372337 \\
23382338 ,
23392339 "{}",
2340 .{status},
2340 .{diag},
23412341 );
23422342 }
23432343
23442344 // Bad type
23452345 {
2346 var status: Status = .{};
2347 defer status.deinit(gpa);
2346 var diag: Diagnostics = .{};
2347 defer diag.deinit(gpa);
23482348 try std.testing.expectError(
23492349 error.ParseZon,
2350 fromSlice(Enum, gpa, "true", &status, .{}),
2350 fromSlice(Enum, gpa, "true", &diag, .{}),
23512351 );
2352 try std.testing.expectFmt("1:1: error: expected enum literal\n", "{}", .{status});
2352 try std.testing.expectFmt("1:1: error: expected enum literal\n", "{}", .{diag});
23532353 }
23542354
23552355 // Test embedded nulls in an identifier
23562356 {
2357 var status: Status = .{};
2358 defer status.deinit(gpa);
2357 var diag: Diagnostics = .{};
2358 defer diag.deinit(gpa);
23592359 try std.testing.expectError(
23602360 error.ParseZon,
2361 fromSlice(Enum, gpa, ".@\"\\x00\"", &status, .{}),
2361 fromSlice(Enum, gpa, ".@\"\\x00\"", &diag, .{}),
23622362 );
23632363 try std.testing.expectFmt(
23642364 "1:2: error: identifier cannot contain null bytes\n",
23652365 "{}",
2366 .{status},
2366 .{diag},
23672367 );
23682368 }
23692369}
......@@ -2377,24 +2377,24 @@ test "std.zon parse bool" {
23772377
23782378 // Errors
23792379 {
2380 var status: Status = .{};
2381 defer status.deinit(gpa);
2380 var diag: Diagnostics = .{};
2381 defer diag.deinit(gpa);
23822382 try std.testing.expectError(
23832383 error.ParseZon,
2384 fromSlice(bool, gpa, " foo", &status, .{}),
2384 fromSlice(bool, gpa, " foo", &diag, .{}),
23852385 );
23862386 try std.testing.expectFmt(
23872387 \\1:2: error: invalid expression
23882388 \\1:2: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
23892389 \\1:2: note: precede identifier with '.' for an enum literal
23902390 \\
2391 , "{}", .{status});
2391 , "{}", .{diag});
23922392 }
23932393 {
2394 var status: Status = .{};
2395 defer status.deinit(gpa);
2396 try std.testing.expectError(error.ParseZon, fromSlice(bool, gpa, "123", &status, .{}));
2397 try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{}", .{status});
2394 var diag: Diagnostics = .{};
2395 defer diag.deinit(gpa);
2396 try std.testing.expectError(error.ParseZon, fromSlice(bool, gpa, "123", &diag, .{}));
2397 try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{}", .{diag});
23982398 }
23992399}
24002400
......@@ -2456,35 +2456,35 @@ test "std.zon parse int" {
24562456 try fromSlice(i66, gpa, "-36893488147419103232", null, .{}),
24572457 );
24582458 {
2459 var status: Status = .{};
2460 defer status.deinit(gpa);
2459 var diag: Diagnostics = .{};
2460 defer diag.deinit(gpa);
24612461 try std.testing.expectError(error.ParseZon, fromSlice(
24622462 i66,
24632463 gpa,
24642464 "36893488147419103232",
2465 &status,
2465 &diag,
24662466 .{},
24672467 ));
24682468 try std.testing.expectFmt(
24692469 "1:1: error: type 'i66' cannot represent value\n",
24702470 "{}",
2471 .{status},
2471 .{diag},
24722472 );
24732473 }
24742474 {
2475 var status: Status = .{};
2476 defer status.deinit(gpa);
2475 var diag: Diagnostics = .{};
2476 defer diag.deinit(gpa);
24772477 try std.testing.expectError(error.ParseZon, fromSlice(
24782478 i66,
24792479 gpa,
24802480 "-36893488147419103233",
2481 &status,
2481 &diag,
24822482 .{},
24832483 ));
24842484 try std.testing.expectFmt(
24852485 "1:1: error: type 'i66' cannot represent value\n",
24862486 "{}",
2487 .{status},
2487 .{diag},
24882488 );
24892489 }
24902490
......@@ -2567,108 +2567,108 @@ test "std.zon parse int" {
25672567
25682568 // Number with invalid character in the middle
25692569 {
2570 var status: Status = .{};
2571 defer status.deinit(gpa);
2572 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "32a32", &status, .{}));
2570 var diag: Diagnostics = .{};
2571 defer diag.deinit(gpa);
2572 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "32a32", &diag, .{}));
25732573 try std.testing.expectFmt(
25742574 "1:3: error: invalid digit 'a' for decimal base\n",
25752575 "{}",
2576 .{status},
2576 .{diag},
25772577 );
25782578 }
25792579
25802580 // Failing to parse as int
25812581 {
2582 var status: Status = .{};
2583 defer status.deinit(gpa);
2584 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "true", &status, .{}));
2585 try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{}", .{status});
2582 var diag: Diagnostics = .{};
2583 defer diag.deinit(gpa);
2584 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "true", &diag, .{}));
2585 try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{}", .{diag});
25862586 }
25872587
25882588 // Failing because an int is out of range
25892589 {
2590 var status: Status = .{};
2591 defer status.deinit(gpa);
2592 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "256", &status, .{}));
2590 var diag: Diagnostics = .{};
2591 defer diag.deinit(gpa);
2592 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "256", &diag, .{}));
25932593 try std.testing.expectFmt(
25942594 "1:1: error: type 'u8' cannot represent value\n",
25952595 "{}",
2596 .{status},
2596 .{diag},
25972597 );
25982598 }
25992599
26002600 // Failing because a negative int is out of range
26012601 {
2602 var status: Status = .{};
2603 defer status.deinit(gpa);
2604 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-129", &status, .{}));
2602 var diag: Diagnostics = .{};
2603 defer diag.deinit(gpa);
2604 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-129", &diag, .{}));
26052605 try std.testing.expectFmt(
26062606 "1:1: error: type 'i8' cannot represent value\n",
26072607 "{}",
2608 .{status},
2608 .{diag},
26092609 );
26102610 }
26112611
26122612 // Failing because an unsigned int is negative
26132613 {
2614 var status: Status = .{};
2615 defer status.deinit(gpa);
2616 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1", &status, .{}));
2614 var diag: Diagnostics = .{};
2615 defer diag.deinit(gpa);
2616 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1", &diag, .{}));
26172617 try std.testing.expectFmt(
26182618 "1:1: error: type 'u8' cannot represent value\n",
26192619 "{}",
2620 .{status},
2620 .{diag},
26212621 );
26222622 }
26232623
26242624 // Failing because a float is non-whole
26252625 {
2626 var status: Status = .{};
2627 defer status.deinit(gpa);
2628 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "1.5", &status, .{}));
2626 var diag: Diagnostics = .{};
2627 defer diag.deinit(gpa);
2628 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "1.5", &diag, .{}));
26292629 try std.testing.expectFmt(
26302630 "1:1: error: type 'u8' cannot represent value\n",
26312631 "{}",
2632 .{status},
2632 .{diag},
26332633 );
26342634 }
26352635
26362636 // Failing because a float is negative
26372637 {
2638 var status: Status = .{};
2639 defer status.deinit(gpa);
2640 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1.0", &status, .{}));
2638 var diag: Diagnostics = .{};
2639 defer diag.deinit(gpa);
2640 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1.0", &diag, .{}));
26412641 try std.testing.expectFmt(
26422642 "1:1: error: type 'u8' cannot represent value\n",
26432643 "{}",
2644 .{status},
2644 .{diag},
26452645 );
26462646 }
26472647
26482648 // Negative integer zero
26492649 {
2650 var status: Status = .{};
2651 defer status.deinit(gpa);
2652 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-0", &status, .{}));
2650 var diag: Diagnostics = .{};
2651 defer diag.deinit(gpa);
2652 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-0", &diag, .{}));
26532653 try std.testing.expectFmt(
26542654 \\1:2: error: integer literal '-0' is ambiguous
26552655 \\1:2: note: use '0' for an integer zero
26562656 \\1:2: note: use '-0.0' for a floating-point signed zero
26572657 \\
2658 , "{}", .{status});
2658 , "{}", .{diag});
26592659 }
26602660
26612661 // Negative integer zero casted to float
26622662 {
2663 var status: Status = .{};
2664 defer status.deinit(gpa);
2665 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-0", &status, .{}));
2663 var diag: Diagnostics = .{};
2664 defer diag.deinit(gpa);
2665 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-0", &diag, .{}));
26662666 try std.testing.expectFmt(
26672667 \\1:2: error: integer literal '-0' is ambiguous
26682668 \\1:2: note: use '0' for an integer zero
26692669 \\1:2: note: use '-0.0' for a floating-point signed zero
26702670 \\
2671 , "{}", .{status});
2671 , "{}", .{diag});
26722672 }
26732673
26742674 // Negative float 0 is allowed
......@@ -2679,48 +2679,48 @@ test "std.zon parse int" {
26792679
26802680 // Double negation is not allowed
26812681 {
2682 var status: Status = .{};
2683 defer status.deinit(gpa);
2684 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "--2", &status, .{}));
2682 var diag: Diagnostics = .{};
2683 defer diag.deinit(gpa);
2684 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "--2", &diag, .{}));
26852685 try std.testing.expectFmt(
26862686 "1:1: error: expected number or 'inf' after '-'\n",
26872687 "{}",
2688 .{status},
2688 .{diag},
26892689 );
26902690 }
26912691
26922692 {
2693 var status: Status = .{};
2694 defer status.deinit(gpa);
2693 var diag: Diagnostics = .{};
2694 defer diag.deinit(gpa);
26952695 try std.testing.expectError(
26962696 error.ParseZon,
2697 fromSlice(f32, gpa, "--2.0", &status, .{}),
2697 fromSlice(f32, gpa, "--2.0", &diag, .{}),
26982698 );
26992699 try std.testing.expectFmt(
27002700 "1:1: error: expected number or 'inf' after '-'\n",
27012701 "{}",
2702 .{status},
2702 .{diag},
27032703 );
27042704 }
27052705
27062706 // Invalid int literal
27072707 {
2708 var status: Status = .{};
2709 defer status.deinit(gpa);
2710 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0xg", &status, .{}));
2711 try std.testing.expectFmt("1:3: error: invalid digit 'g' for hex base\n", "{}", .{status});
2708 var diag: Diagnostics = .{};
2709 defer diag.deinit(gpa);
2710 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0xg", &diag, .{}));
2711 try std.testing.expectFmt("1:3: error: invalid digit 'g' for hex base\n", "{}", .{diag});
27122712 }
27132713
27142714 // Notes on invalid int literal
27152715 {
2716 var status: Status = .{};
2717 defer status.deinit(gpa);
2718 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0123", &status, .{}));
2716 var diag: Diagnostics = .{};
2717 defer diag.deinit(gpa);
2718 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0123", &diag, .{}));
27192719 try std.testing.expectFmt(
27202720 \\1:1: error: number '0123' has leading zero
27212721 \\1:1: note: use '0o' prefix for octal literals
27222722 \\
2723 , "{}", .{status});
2723 , "{}", .{diag});
27242724 }
27252725}
27262726
......@@ -2728,23 +2728,23 @@ test "std.zon negative char" {
27282728 const gpa = std.testing.allocator;
27292729
27302730 {
2731 var status: Status = .{};
2732 defer status.deinit(gpa);
2733 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-'a'", &status, .{}));
2731 var diag: Diagnostics = .{};
2732 defer diag.deinit(gpa);
2733 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-'a'", &diag, .{}));
27342734 try std.testing.expectFmt(
27352735 "1:1: error: expected number or 'inf' after '-'\n",
27362736 "{}",
2737 .{status},
2737 .{diag},
27382738 );
27392739 }
27402740 {
2741 var status: Status = .{};
2742 defer status.deinit(gpa);
2743 try std.testing.expectError(error.ParseZon, fromSlice(i16, gpa, "-'a'", &status, .{}));
2741 var diag: Diagnostics = .{};
2742 defer diag.deinit(gpa);
2743 try std.testing.expectError(error.ParseZon, fromSlice(i16, gpa, "-'a'", &diag, .{}));
27442744 try std.testing.expectFmt(
27452745 "1:1: error: expected number or 'inf' after '-'\n",
27462746 "{}",
2747 .{status},
2747 .{diag},
27482748 );
27492749 }
27502750}
......@@ -2825,81 +2825,81 @@ test "std.zon parse float" {
28252825
28262826 // Negative nan not allowed
28272827 {
2828 var status: Status = .{};
2829 defer status.deinit(gpa);
2830 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-nan", &status, .{}));
2828 var diag: Diagnostics = .{};
2829 defer diag.deinit(gpa);
2830 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-nan", &diag, .{}));
28312831 try std.testing.expectFmt(
28322832 "1:1: error: expected number or 'inf' after '-'\n",
28332833 "{}",
2834 .{status},
2834 .{diag},
28352835 );
28362836 }
28372837
28382838 // nan as int not allowed
28392839 {
2840 var status: Status = .{};
2841 defer status.deinit(gpa);
2842 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &status, .{}));
2843 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status});
2840 var diag: Diagnostics = .{};
2841 defer diag.deinit(gpa);
2842 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &diag, .{}));
2843 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag});
28442844 }
28452845
28462846 // nan as int not allowed
28472847 {
2848 var status: Status = .{};
2849 defer status.deinit(gpa);
2850 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &status, .{}));
2851 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status});
2848 var diag: Diagnostics = .{};
2849 defer diag.deinit(gpa);
2850 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &diag, .{}));
2851 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag});
28522852 }
28532853
28542854 // inf as int not allowed
28552855 {
2856 var status: Status = .{};
2857 defer status.deinit(gpa);
2858 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "inf", &status, .{}));
2859 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status});
2856 var diag: Diagnostics = .{};
2857 defer diag.deinit(gpa);
2858 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "inf", &diag, .{}));
2859 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag});
28602860 }
28612861
28622862 // -inf as int not allowed
28632863 {
2864 var status: Status = .{};
2865 defer status.deinit(gpa);
2866 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-inf", &status, .{}));
2867 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status});
2864 var diag: Diagnostics = .{};
2865 defer diag.deinit(gpa);
2866 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-inf", &diag, .{}));
2867 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag});
28682868 }
28692869
28702870 // Bad identifier as float
28712871 {
2872 var status: Status = .{};
2873 defer status.deinit(gpa);
2874 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "foo", &status, .{}));
2872 var diag: Diagnostics = .{};
2873 defer diag.deinit(gpa);
2874 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "foo", &diag, .{}));
28752875 try std.testing.expectFmt(
28762876 \\1:1: error: invalid expression
28772877 \\1:1: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
28782878 \\1:1: note: precede identifier with '.' for an enum literal
28792879 \\
2880 , "{}", .{status});
2880 , "{}", .{diag});
28812881 }
28822882
28832883 {
2884 var status: Status = .{};
2885 defer status.deinit(gpa);
2886 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-foo", &status, .{}));
2884 var diag: Diagnostics = .{};
2885 defer diag.deinit(gpa);
2886 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-foo", &diag, .{}));
28872887 try std.testing.expectFmt(
28882888 "1:1: error: expected number or 'inf' after '-'\n",
28892889 "{}",
2890 .{status},
2890 .{diag},
28912891 );
28922892 }
28932893
28942894 // Non float as float
28952895 {
2896 var status: Status = .{};
2897 defer status.deinit(gpa);
2896 var diag: Diagnostics = .{};
2897 defer diag.deinit(gpa);
28982898 try std.testing.expectError(
28992899 error.ParseZon,
2900 fromSlice(f32, gpa, "\"foo\"", &status, .{}),
2900 fromSlice(f32, gpa, "\"foo\"", &diag, .{}),
29012901 );
2902 try std.testing.expectFmt("1:1: error: expected type 'f32'\n", "{}", .{status});
2902 try std.testing.expectFmt("1:1: error: expected type 'f32'\n", "{}", .{diag});
29032903 }
29042904}
29052905
......@@ -3136,69 +3136,69 @@ test "std.zon vector" {
31363136
31373137 // Too few fields
31383138 {
3139 var status: Status = .{};
3140 defer status.deinit(gpa);
3139 var diag: Diagnostics = .{};
3140 defer diag.deinit(gpa);
31413141 try std.testing.expectError(
31423142 error.ParseZon,
3143 fromSlice(@Vector(2, f32), gpa, ".{0.5}", &status, .{}),
3143 fromSlice(@Vector(2, f32), gpa, ".{0.5}", &diag, .{}),
31443144 );
31453145 try std.testing.expectFmt(
31463146 "1:2: error: expected 2 vector elements; found 1\n",
31473147 "{}",
3148 .{status},
3148 .{diag},
31493149 );
31503150 }
31513151
31523152 // Too many fields
31533153 {
3154 var status: Status = .{};
3155 defer status.deinit(gpa);
3154 var diag: Diagnostics = .{};
3155 defer diag.deinit(gpa);
31563156 try std.testing.expectError(
31573157 error.ParseZon,
3158 fromSlice(@Vector(2, f32), gpa, ".{0.5, 1.5, 2.5}", &status, .{}),
3158 fromSlice(@Vector(2, f32), gpa, ".{0.5, 1.5, 2.5}", &diag, .{}),
31593159 );
31603160 try std.testing.expectFmt(
31613161 "1:2: error: expected 2 vector elements; found 3\n",
31623162 "{}",
3163 .{status},
3163 .{diag},
31643164 );
31653165 }
31663166
31673167 // Wrong type fields
31683168 {
3169 var status: Status = .{};
3170 defer status.deinit(gpa);
3169 var diag: Diagnostics = .{};
3170 defer diag.deinit(gpa);
31713171 try std.testing.expectError(
31723172 error.ParseZon,
3173 fromSlice(@Vector(3, f32), gpa, ".{0.5, true, 2.5}", &status, .{}),
3173 fromSlice(@Vector(3, f32), gpa, ".{0.5, true, 2.5}", &diag, .{}),
31743174 );
31753175 try std.testing.expectFmt(
31763176 "1:8: error: expected type 'f32'\n",
31773177 "{}",
3178 .{status},
3178 .{diag},
31793179 );
31803180 }
31813181
31823182 // Wrong type
31833183 {
3184 var status: Status = .{};
3185 defer status.deinit(gpa);
3184 var diag: Diagnostics = .{};
3185 defer diag.deinit(gpa);
31863186 try std.testing.expectError(
31873187 error.ParseZon,
3188 fromSlice(@Vector(3, u8), gpa, "true", &status, .{}),
3188 fromSlice(@Vector(3, u8), gpa, "true", &diag, .{}),
31893189 );
3190 try std.testing.expectFmt("1:1: error: expected type '@Vector(3, u8)'\n", "{}", .{status});
3190 try std.testing.expectFmt("1:1: error: expected type '@Vector(3, u8)'\n", "{}", .{diag});
31913191 }
31923192
31933193 // Elements should get freed on error
31943194 {
3195 var status: Status = .{};
3196 defer status.deinit(gpa);
3195 var diag: Diagnostics = .{};
3196 defer diag.deinit(gpa);
31973197 try std.testing.expectError(
31983198 error.ParseZon,
3199 fromSlice(@Vector(3, *u8), gpa, ".{1, true, 3}", &status, .{}),
3199 fromSlice(@Vector(3, *u8), gpa, ".{1, true, 3}", &diag, .{}),
32003200 );
3201 try std.testing.expectFmt("1:6: error: expected type 'u8'\n", "{}", .{status});
3201 try std.testing.expectFmt("1:6: error: expected type 'u8'\n", "{}", .{diag});
32023202 }
32033203}
32043204
......@@ -3316,133 +3316,133 @@ test "std.zon add pointers" {
33163316
33173317 // Test that optional types are flattened correctly in errors
33183318 {
3319 var status: Status = .{};
3320 defer status.deinit(gpa);
3319 var diag: Diagnostics = .{};
3320 defer diag.deinit(gpa);
33213321 try std.testing.expectError(
33223322 error.ParseZon,
3323 fromSlice(*const ?*const u8, gpa, "true", &status, .{}),
3323 fromSlice(*const ?*const u8, gpa, "true", &diag, .{}),
33243324 );
3325 try std.testing.expectFmt("1:1: error: expected type '?u8'\n", "{}", .{status});
3325 try std.testing.expectFmt("1:1: error: expected type '?u8'\n", "{}", .{diag});
33263326 }
33273327
33283328 {
3329 var status: Status = .{};
3330 defer status.deinit(gpa);
3329 var diag: Diagnostics = .{};
3330 defer diag.deinit(gpa);
33313331 try std.testing.expectError(
33323332 error.ParseZon,
3333 fromSlice(*const ?*const f32, gpa, "true", &status, .{}),
3333 fromSlice(*const ?*const f32, gpa, "true", &diag, .{}),
33343334 );
3335 try std.testing.expectFmt("1:1: error: expected type '?f32'\n", "{}", .{status});
3335 try std.testing.expectFmt("1:1: error: expected type '?f32'\n", "{}", .{diag});
33363336 }
33373337
33383338 {
3339 var status: Status = .{};
3340 defer status.deinit(gpa);
3339 var diag: Diagnostics = .{};
3340 defer diag.deinit(gpa);
33413341 try std.testing.expectError(
33423342 error.ParseZon,
3343 fromSlice(*const ?*const @Vector(3, u8), gpa, "true", &status, .{}),
3343 fromSlice(*const ?*const @Vector(3, u8), gpa, "true", &diag, .{}),
33443344 );
3345 try std.testing.expectFmt("1:1: error: expected type '?@Vector(3, u8)'\n", "{}", .{status});
3345 try std.testing.expectFmt("1:1: error: expected type '?@Vector(3, u8)'\n", "{}", .{diag});
33463346 }
33473347
33483348 {
3349 var status: Status = .{};
3350 defer status.deinit(gpa);
3349 var diag: Diagnostics = .{};
3350 defer diag.deinit(gpa);
33513351 try std.testing.expectError(
33523352 error.ParseZon,
3353 fromSlice(*const ?*const bool, gpa, "10", &status, .{}),
3353 fromSlice(*const ?*const bool, gpa, "10", &diag, .{}),
33543354 );
3355 try std.testing.expectFmt("1:1: error: expected type '?bool'\n", "{}", .{status});
3355 try std.testing.expectFmt("1:1: error: expected type '?bool'\n", "{}", .{diag});
33563356 }
33573357
33583358 {
3359 var status: Status = .{};
3360 defer status.deinit(gpa);
3359 var diag: Diagnostics = .{};
3360 defer diag.deinit(gpa);
33613361 try std.testing.expectError(
33623362 error.ParseZon,
3363 fromSlice(*const ?*const struct { a: i32 }, gpa, "true", &status, .{}),
3363 fromSlice(*const ?*const struct { a: i32 }, gpa, "true", &diag, .{}),
33643364 );
3365 try std.testing.expectFmt("1:1: error: expected optional struct\n", "{}", .{status});
3365 try std.testing.expectFmt("1:1: error: expected optional struct\n", "{}", .{diag});
33663366 }
33673367
33683368 {
3369 var status: Status = .{};
3370 defer status.deinit(gpa);
3369 var diag: Diagnostics = .{};
3370 defer diag.deinit(gpa);
33713371 try std.testing.expectError(
33723372 error.ParseZon,
3373 fromSlice(*const ?*const struct { i32 }, gpa, "true", &status, .{}),
3373 fromSlice(*const ?*const struct { i32 }, gpa, "true", &diag, .{}),
33743374 );
3375 try std.testing.expectFmt("1:1: error: expected optional tuple\n", "{}", .{status});
3375 try std.testing.expectFmt("1:1: error: expected optional tuple\n", "{}", .{diag});
33763376 }
33773377
33783378 {
3379 var status: Status = .{};
3380 defer status.deinit(gpa);
3379 var diag: Diagnostics = .{};
3380 defer diag.deinit(gpa);
33813381 try std.testing.expectError(
33823382 error.ParseZon,
3383 fromSlice(*const ?*const union { x: void }, gpa, "true", &status, .{}),
3383 fromSlice(*const ?*const union { x: void }, gpa, "true", &diag, .{}),
33843384 );
3385 try std.testing.expectFmt("1:1: error: expected optional union\n", "{}", .{status});
3385 try std.testing.expectFmt("1:1: error: expected optional union\n", "{}", .{diag});
33863386 }
33873387
33883388 {
3389 var status: Status = .{};
3390 defer status.deinit(gpa);
3389 var diag: Diagnostics = .{};
3390 defer diag.deinit(gpa);
33913391 try std.testing.expectError(
33923392 error.ParseZon,
3393 fromSlice(*const ?*const [3]u8, gpa, "true", &status, .{}),
3393 fromSlice(*const ?*const [3]u8, gpa, "true", &diag, .{}),
33943394 );
3395 try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{status});
3395 try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{diag});
33963396 }
33973397
33983398 {
3399 var status: Status = .{};
3400 defer status.deinit(gpa);
3399 var diag: Diagnostics = .{};
3400 defer diag.deinit(gpa);
34013401 try std.testing.expectError(
34023402 error.ParseZon,
3403 fromSlice(?[3]u8, gpa, "true", &status, .{}),
3403 fromSlice(?[3]u8, gpa, "true", &diag, .{}),
34043404 );
3405 try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{status});
3405 try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{diag});
34063406 }
34073407
34083408 {
3409 var status: Status = .{};
3410 defer status.deinit(gpa);
3409 var diag: Diagnostics = .{};
3410 defer diag.deinit(gpa);
34113411 try std.testing.expectError(
34123412 error.ParseZon,
3413 fromSlice(*const ?*const []u8, gpa, "true", &status, .{}),
3413 fromSlice(*const ?*const []u8, gpa, "true", &diag, .{}),
34143414 );
3415 try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{status});
3415 try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{diag});
34163416 }
34173417
34183418 {
3419 var status: Status = .{};
3420 defer status.deinit(gpa);
3419 var diag: Diagnostics = .{};
3420 defer diag.deinit(gpa);
34213421 try std.testing.expectError(
34223422 error.ParseZon,
3423 fromSlice(?[]u8, gpa, "true", &status, .{}),
3423 fromSlice(?[]u8, gpa, "true", &diag, .{}),
34243424 );
3425 try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{status});
3425 try std.testing.expectFmt("1:1: error: expected optional array\n", "{}", .{diag});
34263426 }
34273427
34283428 {
3429 var status: Status = .{};
3430 defer status.deinit(gpa);
3429 var diag: Diagnostics = .{};
3430 defer diag.deinit(gpa);
34313431 try std.testing.expectError(
34323432 error.ParseZon,
3433 fromSlice(*const ?*const []const u8, gpa, "true", &status, .{}),
3433 fromSlice(*const ?*const []const u8, gpa, "true", &diag, .{}),
34343434 );
3435 try std.testing.expectFmt("1:1: error: expected optional string\n", "{}", .{status});
3435 try std.testing.expectFmt("1:1: error: expected optional string\n", "{}", .{diag});
34363436 }
34373437
34383438 {
3439 var status: Status = .{};
3440 defer status.deinit(gpa);
3439 var diag: Diagnostics = .{};
3440 defer diag.deinit(gpa);
34413441 try std.testing.expectError(
34423442 error.ParseZon,
3443 fromSlice(*const ?*const enum { foo }, gpa, "true", &status, .{}),
3443 fromSlice(*const ?*const enum { foo }, gpa, "true", &diag, .{}),
34443444 );
3445 try std.testing.expectFmt("1:1: error: expected optional enum literal\n", "{}", .{status});
3445 try std.testing.expectFmt("1:1: error: expected optional enum literal\n", "{}", .{diag});
34463446 }
34473447}
34483448
......@@ -3455,17 +3455,17 @@ test "std.zon stop on node" {
34553455 y: f32,
34563456 };
34573457
3458 var status: Status = .{};
3459 defer status.deinit(gpa);
3460 const result = try fromSlice(Vec2, gpa, ".{ .x = 1.5, .y = 2.5 }", &status, .{});
3458 var diag: Diagnostics = .{};
3459 defer diag.deinit(gpa);
3460 const result = try fromSlice(Vec2, gpa, ".{ .x = 1.5, .y = 2.5 }", &diag, .{});
34613461 try std.testing.expectEqual(result.y, 2.5);
3462 try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.5 }, result.x.get(status.zoir.?));
3462 try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.5 }, result.x.get(diag.zoir.?));
34633463 }
34643464
34653465 {
3466 var status: Status = .{};
3467 defer status.deinit(gpa);
3468 const result = try fromSlice(Zoir.Node.Index, gpa, "1.23", &status, .{});
3469 try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(status.zoir.?));
3466 var diag: Diagnostics = .{};
3467 defer diag.deinit(gpa);
3468 const result = try fromSlice(Zoir.Node.Index, gpa, "1.23", &diag, .{});
3469 try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(diag.zoir.?));
34703470 }
34713471}