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) {...@@ -44,13 +44,13 @@ pub const Error = union(enum) {
44 pub const Iterator = struct {44 pub const Iterator = struct {
45 index: usize = 0,45 index: usize = 0,
46 err: Error,46 err: Error,
47 status: *const Status,47 diag: *const Diagnostics,
4848
49 pub fn next(self: *@This()) ?Note {49 pub fn next(self: *@This()) ?Note {
50 switch (self.err) {50 switch (self.err) {
51 .zoir => |err| {51 .zoir => |err| {
52 if (self.index >= err.note_count) return null;52 if (self.index >= err.note_count) return null;
53 const zoir = self.status.zoir.?;53 const zoir = self.diag.zoir.?;
54 const note = err.getNotes(zoir)[self.index];54 const note = err.getNotes(zoir)[self.index];
55 self.index += 1;55 self.index += 1;
56 return .{ .zoir = note };56 return .{ .zoir = note };
...@@ -80,15 +80,15 @@ pub const Error = union(enum) {...@@ -80,15 +80,15 @@ pub const Error = union(enum) {
80 try writer.writeAll(self);80 try writer.writeAll(self);
81 }81 }
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) {
84 return .{ .data = switch (self) {84 return .{ .data = switch (self) {
85 .zoir => |note| note.msg.get(status.zoir.?),85 .zoir => |note| note.msg.get(diag.zoir.?),
86 .type_check => |note| note.msg,86 .type_check => |note| note.msg,
87 } };87 } };
88 }88 }
8989
90 pub fn getLocation(self: Note, status: *const Status) Ast.Location {90 pub fn getLocation(self: Note, diag: *const Diagnostics) Ast.Location {
91 const ast = status.ast.?;91 const ast = diag.ast.?;
92 switch (self) {92 switch (self) {
93 .zoir => |note| return zoirErrorLocation(ast, note.token, note.node_or_offset),93 .zoir => |note| return zoirErrorLocation(ast, note.token, note.node_or_offset),
94 .type_check => |note| return ast.tokenLocation(note.offset, note.token),94 .type_check => |note| return ast.tokenLocation(note.offset, note.token),
...@@ -98,10 +98,10 @@ pub const Error = union(enum) {...@@ -98,10 +98,10 @@ pub const Error = union(enum) {
9898
99 pub const Iterator = struct {99 pub const Iterator = struct {
100 index: usize = 0,100 index: usize = 0,
101 status: *const Status,101 diag: *const Diagnostics,
102102
103 pub fn next(self: *@This()) ?Error {103 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
106 if (self.index < zoir.compile_errors.len) {106 if (self.index < zoir.compile_errors.len) {
107 const result: Error = .{ .zoir = zoir.compile_errors[self.index] };107 const result: Error = .{ .zoir = zoir.compile_errors[self.index] };
...@@ -109,7 +109,7 @@ pub const Error = union(enum) {...@@ -109,7 +109,7 @@ pub const Error = union(enum) {
109 return result;109 return result;
110 }110 }
111111
112 if (self.status.type_check) |err| {112 if (self.diag.type_check) |err| {
113 if (self.index == zoir.compile_errors.len) {113 if (self.index == zoir.compile_errors.len) {
114 const result: Error = .{ .type_check = err };114 const result: Error = .{ .type_check = err };
115 self.index += 1;115 self.index += 1;
...@@ -156,7 +156,7 @@ pub const Error = union(enum) {...@@ -156,7 +156,7 @@ pub const Error = union(enum) {
156156
157 const FormatMessage = struct {157 const FormatMessage = struct {
158 err: Error,158 err: Error,
159 status: *const Status,159 diag: *const Diagnostics,
160 };160 };
161161
162 fn formatMessage(162 fn formatMessage(
...@@ -168,23 +168,23 @@ pub const Error = union(enum) {...@@ -168,23 +168,23 @@ pub const Error = union(enum) {
168 _ = f;168 _ = f;
169 _ = options;169 _ = options;
170 switch (self.err) {170 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.?)),
172 .type_check => |tc| try writer.writeAll(tc.message),172 .type_check => |tc| try writer.writeAll(tc.message),
173 }173 }
174 }174 }
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) {
177 return .{ .data = .{177 return .{ .data = .{
178 .err = self,178 .err = self,
179 .status = status,179 .diag = diag,
180 } };180 } };
181 }181 }
182182
183 pub fn getLocation(self: @This(), status: *const Status) Ast.Location {183 pub fn getLocation(self: @This(), diag: *const Diagnostics) Ast.Location {
184 const ast = status.ast.?;184 const ast = diag.ast.?;
185 return switch (self) {185 return switch (self) {
186 .zoir => |err| return zoirErrorLocation(186 .zoir => |err| return zoirErrorLocation(
187 status.ast.?,187 diag.ast.?,
188 err.token,188 err.token,
189 err.node_or_offset,189 err.node_or_offset,
190 ),190 ),
...@@ -192,8 +192,8 @@ pub const Error = union(enum) {...@@ -192,8 +192,8 @@ pub const Error = union(enum) {
192 };192 };
193 }193 }
194194
195 pub fn iterateNotes(self: @This(), status: *const Status) Note.Iterator {195 pub fn iterateNotes(self: @This(), diag: *const Diagnostics) Note.Iterator {
196 return .{ .err = self, .status = status };196 return .{ .err = self, .diag = diag };
197 }197 }
198198
199 fn zoirErrorLocation(ast: Ast, maybe_token: Ast.OptionalTokenIndex, node_or_offset: u32) Ast.Location {199 fn zoirErrorLocation(ast: Ast, maybe_token: Ast.OptionalTokenIndex, node_or_offset: u32) Ast.Location {
...@@ -210,26 +210,26 @@ pub const Error = union(enum) {...@@ -210,26 +210,26 @@ pub const Error = union(enum) {
210};210};
211211
212/// Information about the success or failure of a parse.212/// Information about the success or failure of a parse.
213pub const Status = struct {213pub const Diagnostics = struct {
214 ast: ?Ast = null,214 ast: ?Ast = null,
215 zoir: ?Zoir = null,215 zoir: ?Zoir = null,
216 type_check: ?Error.TypeCheckFailure = null,216 type_check: ?Error.TypeCheckFailure = null,
217217
218 fn assertEmpty(self: Status) void {218 fn assertEmpty(self: Diagnostics) void {
219 assert(self.ast == null);219 assert(self.ast == null);
220 assert(self.zoir == null);220 assert(self.zoir == null);
221 assert(self.type_check == null);221 assert(self.type_check == null);
222 }222 }
223223
224 pub fn deinit(self: *Status, gpa: Allocator) void {224 pub fn deinit(self: *Diagnostics, gpa: Allocator) void {
225 if (self.ast) |*ast| ast.deinit(gpa);225 if (self.ast) |*ast| ast.deinit(gpa);
226 if (self.zoir) |*zoir| zoir.deinit(gpa);226 if (self.zoir) |*zoir| zoir.deinit(gpa);
227 if (self.type_check) |tc| tc.deinit(gpa);227 if (self.type_check) |tc| tc.deinit(gpa);
228 self.* = undefined;228 self.* = undefined;
229 }229 }
230230
231 pub fn iterateErrors(self: *const Status) Error.Iterator {231 pub fn iterateErrors(self: *const Diagnostics) Error.Iterator {
232 return .{ .status = self };232 return .{ .diag = self };
233 }233 }
234234
235 pub fn format(235 pub fn format(
...@@ -266,7 +266,7 @@ pub const Status = struct {...@@ -266,7 +266,7 @@ pub const Status = struct {
266/// invalid or can not be deserialized into type `T`.266/// invalid or can not be deserialized into type `T`.
267///267///
268/// When the parser returns `error.ParseZon`, it will also store a human readable explanation in268/// 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 `.{}`.
270pub fn fromSlice(270pub fn fromSlice(
271 /// The type to deserialize into. May not be or contain any of the following types:271 /// The type to deserialize into. May not be or contain any of the following types:
272 /// * Any comptime-only type, except in a comptime field272 /// * Any comptime-only type, except in a comptime field
...@@ -283,22 +283,22 @@ pub fn fromSlice(...@@ -283,22 +283,22 @@ pub fn fromSlice(
283 T: type,283 T: type,
284 gpa: Allocator,284 gpa: Allocator,
285 source: [:0]const u8,285 source: [:0]const u8,
286 status: ?*Status,286 diag: ?*Diagnostics,
287 options: Options,287 options: Options,
288) error{ OutOfMemory, ParseZon }!T {288) error{ OutOfMemory, ParseZon }!T {
289 if (status) |s| s.assertEmpty();289 if (diag) |s| s.assertEmpty();
290290
291 var ast = try std.zig.Ast.parse(gpa, source, .zon);291 var ast = try std.zig.Ast.parse(gpa, source, .zon);
292 defer if (status == null) ast.deinit(gpa);292 defer if (diag == null) ast.deinit(gpa);
293 if (status) |s| s.ast = ast;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,295 // If there's no diagnostics, Zoir exists for the lifetime of this function. If there is a
296 // ownership is transferred to status.296 // diagnostics, ownership is transferred to diagnostics.
297 var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false });297 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.* = .{};300 if (diag) |s| s.* = .{};
301 return fromZoir(T, gpa, ast, zoir, status, options);301 return fromZoir(T, gpa, ast, zoir, diag, options);
302}302}
303303
304/// Like `fromSlice`, but operates on `Zoir` instead of ZON source.304/// Like `fromSlice`, but operates on `Zoir` instead of ZON source.
...@@ -307,10 +307,10 @@ pub fn fromZoir(...@@ -307,10 +307,10 @@ pub fn fromZoir(
307 gpa: Allocator,307 gpa: Allocator,
308 ast: Ast,308 ast: Ast,
309 zoir: Zoir,309 zoir: Zoir,
310 status: ?*Status,310 diag: ?*Diagnostics,
311 options: Options,311 options: Options,
312) error{ OutOfMemory, ParseZon }!T {312) error{ OutOfMemory, ParseZon }!T {
313 return fromZoirNode(T, gpa, ast, zoir, .root, status, options);313 return fromZoirNode(T, gpa, ast, zoir, .root, diag, options);
314}314}
315315
316/// Like `fromZoir`, but the parse starts on `node` instead of root.316/// Like `fromZoir`, but the parse starts on `node` instead of root.
...@@ -320,12 +320,12 @@ pub fn fromZoirNode(...@@ -320,12 +320,12 @@ pub fn fromZoirNode(
320 ast: Ast,320 ast: Ast,
321 zoir: Zoir,321 zoir: Zoir,
322 node: Zoir.Node.Index,322 node: Zoir.Node.Index,
323 status: ?*Status,323 diag: ?*Diagnostics,
324 options: Options,324 options: Options,
325) error{ OutOfMemory, ParseZon }!T {325) error{ OutOfMemory, ParseZon }!T {
326 comptime assert(canParseType(T));326 comptime assert(canParseType(T));
327327
328 if (status) |s| {328 if (diag) |s| {
329 s.assertEmpty();329 s.assertEmpty();
330 s.ast = ast;330 s.ast = ast;
331 s.zoir = zoir;331 s.zoir = zoir;
...@@ -340,7 +340,7 @@ pub fn fromZoirNode(...@@ -340,7 +340,7 @@ pub fn fromZoirNode(
340 .ast = ast,340 .ast = ast,
341 .zoir = zoir,341 .zoir = zoir,
342 .options = options,342 .options = options,
343 .status = status,343 .diag = diag,
344 };344 };
345345
346 return parser.parseExpr(T, node);346 return parser.parseExpr(T, node);
...@@ -421,7 +421,7 @@ const Parser = struct {...@@ -421,7 +421,7 @@ const Parser = struct {
421 gpa: Allocator,421 gpa: Allocator,
422 ast: Ast,422 ast: Ast,
423 zoir: Zoir,423 zoir: Zoir,
424 status: ?*Status,424 diag: ?*Diagnostics,
425 options: Options,425 options: Options,
426426
427 fn parseExpr(self: *@This(), T: type, node: Zoir.Node.Index) error{ ParseZon, OutOfMemory }!T {427 fn parseExpr(self: *@This(), T: type, node: Zoir.Node.Index) error{ ParseZon, OutOfMemory }!T {
...@@ -988,7 +988,7 @@ const Parser = struct {...@@ -988,7 +988,7 @@ const Parser = struct {
988 ) error{ OutOfMemory, ParseZon } {988 ) error{ OutOfMemory, ParseZon } {
989 @branchHint(.cold);989 @branchHint(.cold);
990 comptime assert(args.len > 0);990 comptime assert(args.len > 0);
991 if (self.status) |s| s.type_check = .{991 if (self.diag) |s| s.type_check = .{
992 .token = token,992 .token = token,
993 .offset = offset,993 .offset = offset,
994 .message = std.fmt.allocPrint(self.gpa, fmt, args) catch |err| {994 .message = std.fmt.allocPrint(self.gpa, fmt, args) catch |err| {
...@@ -1017,7 +1017,7 @@ const Parser = struct {...@@ -1017,7 +1017,7 @@ const Parser = struct {
1017 failure: Error.TypeCheckFailure,1017 failure: Error.TypeCheckFailure,
1018 ) error{ParseZon} {1018 ) error{ParseZon} {
1019 @branchHint(.cold);1019 @branchHint(.cold);
1020 if (self.status) |s| s.type_check = failure;1020 if (self.diag) |s| s.type_check = failure;
1021 return error.ParseZon;1021 return error.ParseZon;
1022 }1022 }
10231023
...@@ -1283,13 +1283,13 @@ test "std.zon requiresAllocator" {...@@ -1283,13 +1283,13 @@ test "std.zon requiresAllocator" {
12831283
1284test "std.zon ast errors" {1284test "std.zon ast errors" {
1285 const gpa = std.testing.allocator;1285 const gpa = std.testing.allocator;
1286 var status: Status = .{};1286 var diag: Diagnostics = .{};
1287 defer status.deinit(gpa);1287 defer diag.deinit(gpa);
1288 try std.testing.expectError(1288 try std.testing.expectError(
1289 error.ParseZon,1289 error.ParseZon,
1290 fromSlice(struct {}, gpa, ".{.x = 1 .y = 2}", &status, .{}),1290 fromSlice(struct {}, gpa, ".{.x = 1 .y = 2}", &diag, .{}),
1291 );1291 );
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});
1293}1293}
12941294
1295test "std.zon comments" {1295test "std.zon comments" {
...@@ -1302,17 +1302,17 @@ test "std.zon comments" {...@@ -1302,17 +1302,17 @@ test "std.zon comments" {
1302 , null, .{}));1302 , null, .{}));
13031303
1304 {1304 {
1305 var status: Status = .{};1305 var diag: Diagnostics = .{};
1306 defer status.deinit(gpa);1306 defer diag.deinit(gpa);
1307 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa,1307 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa,
1308 \\//! comment1308 \\//! comment
1309 \\10 // comment1309 \\10 // comment
1310 \\// comment1310 \\// comment
1311 , &status, .{}));1311 , &diag, .{}));
1312 try std.testing.expectFmt(1312 try std.testing.expectFmt(
1313 "1:1: error: expected expression, found 'a document comment'\n",1313 "1:1: error: expected expression, found 'a document comment'\n",
1314 "{}",1314 "{}",
1315 .{status},1315 .{diag},
1316 );1316 );
1317 }1317 }
1318}1318}
...@@ -1323,16 +1323,16 @@ test "std.zon failure/oom formatting" {...@@ -1323,16 +1323,16 @@ test "std.zon failure/oom formatting" {
1323 .fail_index = 0,1323 .fail_index = 0,
1324 .resize_fail_index = 0,1324 .resize_fail_index = 0,
1325 });1325 });
1326 var status: Status = .{};1326 var diag: Diagnostics = .{};
1327 defer status.deinit(gpa);1327 defer diag.deinit(gpa);
1328 try std.testing.expectError(error.OutOfMemory, fromSlice(1328 try std.testing.expectError(error.OutOfMemory, fromSlice(
1329 []const u8,1329 []const u8,
1330 failing_allocator.allocator(),1330 failing_allocator.allocator(),
1331 "\"foo\"",1331 "\"foo\"",
1332 &status,1332 &diag,
1333 .{},1333 .{},
1334 ));1334 ));
1335 try std.testing.expectFmt("", "{}", .{status});1335 try std.testing.expectFmt("", "{}", .{diag});
1336}1336}
13371337
1338test "std.zon fromSlice syntax error" {1338test "std.zon fromSlice syntax error" {
...@@ -1401,11 +1401,11 @@ test "std.zon unions" {...@@ -1401,11 +1401,11 @@ test "std.zon unions" {
1401 // Unknown field1401 // Unknown field
1402 {1402 {
1403 const Union = union { x: f32, y: f32 };1403 const Union = union { x: f32, y: f32 };
1404 var status: Status = .{};1404 var diag: Diagnostics = .{};
1405 defer status.deinit(gpa);1405 defer diag.deinit(gpa);
1406 try std.testing.expectError(1406 try std.testing.expectError(
1407 error.ParseZon,1407 error.ParseZon,
1408 fromSlice(Union, gpa, ".{.z=2.5}", &status, .{}),1408 fromSlice(Union, gpa, ".{.z=2.5}", &diag, .{}),
1409 );1409 );
1410 try std.testing.expectFmt(1410 try std.testing.expectFmt(
1411 \\1:4: error: unexpected field 'z'1411 \\1:4: error: unexpected field 'z'
...@@ -1413,78 +1413,78 @@ test "std.zon unions" {...@@ -1413,78 +1413,78 @@ test "std.zon unions" {
1413 \\1413 \\
1414 ,1414 ,
1415 "{}",1415 "{}",
1416 .{status},1416 .{diag},
1417 );1417 );
1418 }1418 }
14191419
1420 // Explicit void field1420 // Explicit void field
1421 {1421 {
1422 const Union = union(enum) { x: void };1422 const Union = union(enum) { x: void };
1423 var status: Status = .{};1423 var diag: Diagnostics = .{};
1424 defer status.deinit(gpa);1424 defer diag.deinit(gpa);
1425 try std.testing.expectError(1425 try std.testing.expectError(
1426 error.ParseZon,1426 error.ParseZon,
1427 fromSlice(Union, gpa, ".{.x=1}", &status, .{}),1427 fromSlice(Union, gpa, ".{.x=1}", &diag, .{}),
1428 );1428 );
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});
1430 }1430 }
14311431
1432 // Extra field1432 // Extra field
1433 {1433 {
1434 const Union = union { x: f32, y: bool };1434 const Union = union { x: f32, y: bool };
1435 var status: Status = .{};1435 var diag: Diagnostics = .{};
1436 defer status.deinit(gpa);1436 defer diag.deinit(gpa);
1437 try std.testing.expectError(1437 try std.testing.expectError(
1438 error.ParseZon,1438 error.ParseZon,
1439 fromSlice(Union, gpa, ".{.x = 1.5, .y = true}", &status, .{}),1439 fromSlice(Union, gpa, ".{.x = 1.5, .y = true}", &diag, .{}),
1440 );1440 );
1441 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status});1441 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag});
1442 }1442 }
14431443
1444 // No fields1444 // No fields
1445 {1445 {
1446 const Union = union { x: f32, y: bool };1446 const Union = union { x: f32, y: bool };
1447 var status: Status = .{};1447 var diag: Diagnostics = .{};
1448 defer status.deinit(gpa);1448 defer diag.deinit(gpa);
1449 try std.testing.expectError(1449 try std.testing.expectError(
1450 error.ParseZon,1450 error.ParseZon,
1451 fromSlice(Union, gpa, ".{}", &status, .{}),1451 fromSlice(Union, gpa, ".{}", &diag, .{}),
1452 );1452 );
1453 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status});1453 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag});
1454 }1454 }
14551455
1456 // Enum literals cannot coerce into untagged unions1456 // Enum literals cannot coerce into untagged unions
1457 {1457 {
1458 const Union = union { x: void };1458 const Union = union { x: void };
1459 var status: Status = .{};1459 var diag: Diagnostics = .{};
1460 defer status.deinit(gpa);1460 defer diag.deinit(gpa);
1461 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &status, .{}));1461 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &diag, .{}));
1462 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status});1462 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag});
1463 }1463 }
14641464
1465 // Unknown field for enum literal coercion1465 // Unknown field for enum literal coercion
1466 {1466 {
1467 const Union = union(enum) { x: void };1467 const Union = union(enum) { x: void };
1468 var status: Status = .{};1468 var diag: Diagnostics = .{};
1469 defer status.deinit(gpa);1469 defer diag.deinit(gpa);
1470 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".y", &status, .{}));1470 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".y", &diag, .{}));
1471 try std.testing.expectFmt(1471 try std.testing.expectFmt(
1472 \\1:2: error: unexpected field 'y'1472 \\1:2: error: unexpected field 'y'
1473 \\1:2: note: supported: 'x'1473 \\1:2: note: supported: 'x'
1474 \\1474 \\
1475 ,1475 ,
1476 "{}",1476 "{}",
1477 .{status},1477 .{diag},
1478 );1478 );
1479 }1479 }
14801480
1481 // Non void field for enum literal coercion1481 // Non void field for enum literal coercion
1482 {1482 {
1483 const Union = union(enum) { x: f32 };1483 const Union = union(enum) { x: f32 };
1484 var status: Status = .{};1484 var diag: Diagnostics = .{};
1485 defer status.deinit(gpa);1485 defer diag.deinit(gpa);
1486 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &status, .{}));1486 try std.testing.expectError(error.ParseZon, fromSlice(Union, gpa, ".x", &diag, .{}));
1487 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{status});1487 try std.testing.expectFmt("1:2: error: expected union\n", "{}", .{diag});
1488 }1488 }
1489}1489}
14901490
...@@ -1529,11 +1529,11 @@ test "std.zon structs" {...@@ -1529,11 +1529,11 @@ test "std.zon structs" {
1529 // Unknown field1529 // Unknown field
1530 {1530 {
1531 const Vec2 = struct { x: f32, y: f32 };1531 const Vec2 = struct { x: f32, y: f32 };
1532 var status: Status = .{};1532 var diag: Diagnostics = .{};
1533 defer status.deinit(gpa);1533 defer diag.deinit(gpa);
1534 try std.testing.expectError(1534 try std.testing.expectError(
1535 error.ParseZon,1535 error.ParseZon,
1536 fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &status, .{}),1536 fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &diag, .{}),
1537 );1537 );
1538 try std.testing.expectFmt(1538 try std.testing.expectFmt(
1539 \\1:12: error: unexpected field 'z'1539 \\1:12: error: unexpected field 'z'
...@@ -1541,24 +1541,24 @@ test "std.zon structs" {...@@ -1541,24 +1541,24 @@ test "std.zon structs" {
1541 \\1541 \\
1542 ,1542 ,
1543 "{}",1543 "{}",
1544 .{status},1544 .{diag},
1545 );1545 );
1546 }1546 }
15471547
1548 // Duplicate field1548 // Duplicate field
1549 {1549 {
1550 const Vec2 = struct { x: f32, y: f32 };1550 const Vec2 = struct { x: f32, y: f32 };
1551 var status: Status = .{};1551 var diag: Diagnostics = .{};
1552 defer status.deinit(gpa);1552 defer diag.deinit(gpa);
1553 try std.testing.expectError(1553 try std.testing.expectError(
1554 error.ParseZon,1554 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, .{}),
1556 );1556 );
1557 try std.testing.expectFmt(1557 try std.testing.expectFmt(
1558 \\1:4: error: duplicate struct field name1558 \\1:4: error: duplicate struct field name
1559 \\1:12: note: duplicate name here1559 \\1:12: note: duplicate name here
1560 \\1560 \\
1561 , "{}", .{status});1561 , "{}", .{diag});
1562 }1562 }
15631563
1564 // Ignore unknown fields1564 // Ignore unknown fields
...@@ -1573,29 +1573,29 @@ test "std.zon structs" {...@@ -1573,29 +1573,29 @@ test "std.zon structs" {
1573 // Unknown field when struct has no fields (regression test)1573 // Unknown field when struct has no fields (regression test)
1574 {1574 {
1575 const Vec2 = struct {};1575 const Vec2 = struct {};
1576 var status: Status = .{};1576 var diag: Diagnostics = .{};
1577 defer status.deinit(gpa);1577 defer diag.deinit(gpa);
1578 try std.testing.expectError(1578 try std.testing.expectError(
1579 error.ParseZon,1579 error.ParseZon,
1580 fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &status, .{}),1580 fromSlice(Vec2, gpa, ".{.x=1.5, .z=2.5}", &diag, .{}),
1581 );1581 );
1582 try std.testing.expectFmt(1582 try std.testing.expectFmt(
1583 \\1:4: error: unexpected field 'x'1583 \\1:4: error: unexpected field 'x'
1584 \\1:4: note: none expected1584 \\1:4: note: none expected
1585 \\1585 \\
1586 , "{}", .{status});1586 , "{}", .{diag});
1587 }1587 }
15881588
1589 // Missing field1589 // Missing field
1590 {1590 {
1591 const Vec2 = struct { x: f32, y: f32 };1591 const Vec2 = struct { x: f32, y: f32 };
1592 var status: Status = .{};1592 var diag: Diagnostics = .{};
1593 defer status.deinit(gpa);1593 defer diag.deinit(gpa);
1594 try std.testing.expectError(1594 try std.testing.expectError(
1595 error.ParseZon,1595 error.ParseZon,
1596 fromSlice(Vec2, gpa, ".{.x=1.5}", &status, .{}),1596 fromSlice(Vec2, gpa, ".{.x=1.5}", &diag, .{}),
1597 );1597 );
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});
1599 }1599 }
16001600
1601 // Default field1601 // Default field
...@@ -1615,14 +1615,14 @@ test "std.zon structs" {...@@ -1615,14 +1615,14 @@ test "std.zon structs" {
1615 // Comptime field assignment1615 // Comptime field assignment
1616 {1616 {
1617 const Vec2 = struct { x: f32, comptime y: f32 = 1.5 };1617 const Vec2 = struct { x: f32, comptime y: f32 = 1.5 };
1618 var status: Status = .{};1618 var diag: Diagnostics = .{};
1619 defer status.deinit(gpa);1619 defer diag.deinit(gpa);
1620 const parsed = fromSlice(Vec2, gpa, ".{.x = 1.2, .y = 1.5}", &status, .{});1620 const parsed = fromSlice(Vec2, gpa, ".{.x = 1.2, .y = 1.5}", &diag, .{});
1621 try std.testing.expectError(error.ParseZon, parsed);1621 try std.testing.expectError(error.ParseZon, parsed);
1622 try std.testing.expectFmt(1622 try std.testing.expectFmt(
1623 \\1:18: error: cannot initialize comptime field1623 \\1:18: error: cannot initialize comptime field
1624 \\1624 \\
1625 , "{}", .{status});1625 , "{}", .{diag});
1626 }1626 }
16271627
1628 // Enum field (regression test, we were previously getting the field name in an1628 // Enum field (regression test, we were previously getting the field name in an
...@@ -1644,52 +1644,52 @@ test "std.zon structs" {...@@ -1644,52 +1644,52 @@ test "std.zon structs" {
1644 {1644 {
1645 // Structs1645 // Structs
1646 {1646 {
1647 var status: Status = .{};1647 var diag: Diagnostics = .{};
1648 defer status.deinit(gpa);1648 defer diag.deinit(gpa);
1649 const parsed = fromSlice(struct {}, gpa, "Empty{}", &status, .{});1649 const parsed = fromSlice(struct {}, gpa, "Empty{}", &diag, .{});
1650 try std.testing.expectError(error.ParseZon, parsed);1650 try std.testing.expectError(error.ParseZon, parsed);
1651 try std.testing.expectFmt(1651 try std.testing.expectFmt(
1652 \\1:1: error: types are not available in ZON1652 \\1:1: error: types are not available in ZON
1653 \\1:1: note: replace the type with '.'1653 \\1:1: note: replace the type with '.'
1654 \\1654 \\
1655 , "{}", .{status});1655 , "{}", .{diag});
1656 }1656 }
16571657
1658 // Arrays1658 // Arrays
1659 {1659 {
1660 var status: Status = .{};1660 var diag: Diagnostics = .{};
1661 defer status.deinit(gpa);1661 defer diag.deinit(gpa);
1662 const parsed = fromSlice([3]u8, gpa, "[3]u8{1, 2, 3}", &status, .{});1662 const parsed = fromSlice([3]u8, gpa, "[3]u8{1, 2, 3}", &diag, .{});
1663 try std.testing.expectError(error.ParseZon, parsed);1663 try std.testing.expectError(error.ParseZon, parsed);
1664 try std.testing.expectFmt(1664 try std.testing.expectFmt(
1665 \\1:1: error: types are not available in ZON1665 \\1:1: error: types are not available in ZON
1666 \\1:1: note: replace the type with '.'1666 \\1:1: note: replace the type with '.'
1667 \\1667 \\
1668 , "{}", .{status});1668 , "{}", .{diag});
1669 }1669 }
16701670
1671 // Slices1671 // Slices
1672 {1672 {
1673 var status: Status = .{};1673 var diag: Diagnostics = .{};
1674 defer status.deinit(gpa);1674 defer diag.deinit(gpa);
1675 const parsed = fromSlice([]u8, gpa, "[]u8{1, 2, 3}", &status, .{});1675 const parsed = fromSlice([]u8, gpa, "[]u8{1, 2, 3}", &diag, .{});
1676 try std.testing.expectError(error.ParseZon, parsed);1676 try std.testing.expectError(error.ParseZon, parsed);
1677 try std.testing.expectFmt(1677 try std.testing.expectFmt(
1678 \\1:1: error: types are not available in ZON1678 \\1:1: error: types are not available in ZON
1679 \\1:1: note: replace the type with '.'1679 \\1:1: note: replace the type with '.'
1680 \\1680 \\
1681 , "{}", .{status});1681 , "{}", .{diag});
1682 }1682 }
16831683
1684 // Tuples1684 // Tuples
1685 {1685 {
1686 var status: Status = .{};1686 var diag: Diagnostics = .{};
1687 defer status.deinit(gpa);1687 defer diag.deinit(gpa);
1688 const parsed = fromSlice(1688 const parsed = fromSlice(
1689 struct { u8, u8, u8 },1689 struct { u8, u8, u8 },
1690 gpa,1690 gpa,
1691 "Tuple{1, 2, 3}",1691 "Tuple{1, 2, 3}",
1692 &status,1692 &diag,
1693 .{},1693 .{},
1694 );1694 );
1695 try std.testing.expectError(error.ParseZon, parsed);1695 try std.testing.expectError(error.ParseZon, parsed);
...@@ -1697,20 +1697,20 @@ test "std.zon structs" {...@@ -1697,20 +1697,20 @@ test "std.zon structs" {
1697 \\1:1: error: types are not available in ZON1697 \\1:1: error: types are not available in ZON
1698 \\1:1: note: replace the type with '.'1698 \\1:1: note: replace the type with '.'
1699 \\1699 \\
1700 , "{}", .{status});1700 , "{}", .{diag});
1701 }1701 }
17021702
1703 // Nested1703 // Nested
1704 {1704 {
1705 var status: Status = .{};1705 var diag: Diagnostics = .{};
1706 defer status.deinit(gpa);1706 defer diag.deinit(gpa);
1707 const parsed = fromSlice(struct {}, gpa, ".{ .x = Tuple{1, 2, 3} }", &status, .{});1707 const parsed = fromSlice(struct {}, gpa, ".{ .x = Tuple{1, 2, 3} }", &diag, .{});
1708 try std.testing.expectError(error.ParseZon, parsed);1708 try std.testing.expectError(error.ParseZon, parsed);
1709 try std.testing.expectFmt(1709 try std.testing.expectFmt(
1710 \\1:9: error: types are not available in ZON1710 \\1:9: error: types are not available in ZON
1711 \\1:9: note: replace the type with '.'1711 \\1:9: note: replace the type with '.'
1712 \\1712 \\
1713 , "{}", .{status});1713 , "{}", .{diag});
1714 }1714 }
1715 }1715 }
1716}1716}
...@@ -1749,53 +1749,53 @@ test "std.zon tuples" {...@@ -1749,53 +1749,53 @@ test "std.zon tuples" {
1749 // Extra field1749 // Extra field
1750 {1750 {
1751 const Tuple = struct { f32, bool };1751 const Tuple = struct { f32, bool };
1752 var status: Status = .{};1752 var diag: Diagnostics = .{};
1753 defer status.deinit(gpa);1753 defer diag.deinit(gpa);
1754 try std.testing.expectError(1754 try std.testing.expectError(
1755 error.ParseZon,1755 error.ParseZon,
1756 fromSlice(Tuple, gpa, ".{0.5, true, 123}", &status, .{}),1756 fromSlice(Tuple, gpa, ".{0.5, true, 123}", &diag, .{}),
1757 );1757 );
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});
1759 }1759 }
17601760
1761 // Extra field1761 // Extra field
1762 {1762 {
1763 const Tuple = struct { f32, bool };1763 const Tuple = struct { f32, bool };
1764 var status: Status = .{};1764 var diag: Diagnostics = .{};
1765 defer status.deinit(gpa);1765 defer diag.deinit(gpa);
1766 try std.testing.expectError(1766 try std.testing.expectError(
1767 error.ParseZon,1767 error.ParseZon,
1768 fromSlice(Tuple, gpa, ".{0.5}", &status, .{}),1768 fromSlice(Tuple, gpa, ".{0.5}", &diag, .{}),
1769 );1769 );
1770 try std.testing.expectFmt(1770 try std.testing.expectFmt(
1771 "1:2: error: missing tuple field with index 1\n",1771 "1:2: error: missing tuple field with index 1\n",
1772 "{}",1772 "{}",
1773 .{status},1773 .{diag},
1774 );1774 );
1775 }1775 }
17761776
1777 // Tuple with unexpected field names1777 // Tuple with unexpected field names
1778 {1778 {
1779 const Tuple = struct { f32 };1779 const Tuple = struct { f32 };
1780 var status: Status = .{};1780 var diag: Diagnostics = .{};
1781 defer status.deinit(gpa);1781 defer diag.deinit(gpa);
1782 try std.testing.expectError(1782 try std.testing.expectError(
1783 error.ParseZon,1783 error.ParseZon,
1784 fromSlice(Tuple, gpa, ".{.foo = 10.0}", &status, .{}),1784 fromSlice(Tuple, gpa, ".{.foo = 10.0}", &diag, .{}),
1785 );1785 );
1786 try std.testing.expectFmt("1:2: error: expected tuple\n", "{}", .{status});1786 try std.testing.expectFmt("1:2: error: expected tuple\n", "{}", .{diag});
1787 }1787 }
17881788
1789 // Struct with missing field names1789 // Struct with missing field names
1790 {1790 {
1791 const Struct = struct { foo: f32 };1791 const Struct = struct { foo: f32 };
1792 var status: Status = .{};1792 var diag: Diagnostics = .{};
1793 defer status.deinit(gpa);1793 defer diag.deinit(gpa);
1794 try std.testing.expectError(1794 try std.testing.expectError(
1795 error.ParseZon,1795 error.ParseZon,
1796 fromSlice(Struct, gpa, ".{10.0}", &status, .{}),1796 fromSlice(Struct, gpa, ".{10.0}", &diag, .{}),
1797 );1797 );
1798 try std.testing.expectFmt("1:2: error: expected struct\n", "{}", .{status});1798 try std.testing.expectFmt("1:2: error: expected struct\n", "{}", .{diag});
1799 }1799 }
18001800
1801 // Comptime field1801 // Comptime field
...@@ -1808,14 +1808,14 @@ test "std.zon tuples" {...@@ -1808,14 +1808,14 @@ test "std.zon tuples" {
1808 // Comptime field assignment1808 // Comptime field assignment
1809 {1809 {
1810 const Vec2 = struct { f32, comptime f32 = 1.5 };1810 const Vec2 = struct { f32, comptime f32 = 1.5 };
1811 var status: Status = .{};1811 var diag: Diagnostics = .{};
1812 defer status.deinit(gpa);1812 defer diag.deinit(gpa);
1813 const parsed = fromSlice(Vec2, gpa, ".{ 1.2, 1.5}", &status, .{});1813 const parsed = fromSlice(Vec2, gpa, ".{ 1.2, 1.5}", &diag, .{});
1814 try std.testing.expectError(error.ParseZon, parsed);1814 try std.testing.expectError(error.ParseZon, parsed);
1815 try std.testing.expectFmt(1815 try std.testing.expectFmt(
1816 \\1:9: error: cannot initialize comptime field1816 \\1:9: error: cannot initialize comptime field
1817 \\1817 \\
1818 , "{}", .{status});1818 , "{}", .{diag});
1819 }1819 }
1820}1820}
18211821
...@@ -1919,61 +1919,61 @@ test "std.zon arrays and slices" {...@@ -1919,61 +1919,61 @@ test "std.zon arrays and slices" {
19191919
1920 // Expect 0 find 31920 // Expect 0 find 3
1921 {1921 {
1922 var status: Status = .{};1922 var diag: Diagnostics = .{};
1923 defer status.deinit(gpa);1923 defer diag.deinit(gpa);
1924 try std.testing.expectError(1924 try std.testing.expectError(
1925 error.ParseZon,1925 error.ParseZon,
1926 fromSlice([0]u8, gpa, ".{'a', 'b', 'c'}", &status, .{}),1926 fromSlice([0]u8, gpa, ".{'a', 'b', 'c'}", &diag, .{}),
1927 );1927 );
1928 try std.testing.expectFmt(1928 try std.testing.expectFmt(
1929 "1:3: error: index 0 outside of array of length 0\n",1929 "1:3: error: index 0 outside of array of length 0\n",
1930 "{}",1930 "{}",
1931 .{status},1931 .{diag},
1932 );1932 );
1933 }1933 }
19341934
1935 // Expect 1 find 21935 // Expect 1 find 2
1936 {1936 {
1937 var status: Status = .{};1937 var diag: Diagnostics = .{};
1938 defer status.deinit(gpa);1938 defer diag.deinit(gpa);
1939 try std.testing.expectError(1939 try std.testing.expectError(
1940 error.ParseZon,1940 error.ParseZon,
1941 fromSlice([1]u8, gpa, ".{'a', 'b'}", &status, .{}),1941 fromSlice([1]u8, gpa, ".{'a', 'b'}", &diag, .{}),
1942 );1942 );
1943 try std.testing.expectFmt(1943 try std.testing.expectFmt(
1944 "1:8: error: index 1 outside of array of length 1\n",1944 "1:8: error: index 1 outside of array of length 1\n",
1945 "{}",1945 "{}",
1946 .{status},1946 .{diag},
1947 );1947 );
1948 }1948 }
19491949
1950 // Expect 2 find 11950 // Expect 2 find 1
1951 {1951 {
1952 var status: Status = .{};1952 var diag: Diagnostics = .{};
1953 defer status.deinit(gpa);1953 defer diag.deinit(gpa);
1954 try std.testing.expectError(1954 try std.testing.expectError(
1955 error.ParseZon,1955 error.ParseZon,
1956 fromSlice([2]u8, gpa, ".{'a'}", &status, .{}),1956 fromSlice([2]u8, gpa, ".{'a'}", &diag, .{}),
1957 );1957 );
1958 try std.testing.expectFmt(1958 try std.testing.expectFmt(
1959 "1:2: error: expected 2 array elements; found 1\n",1959 "1:2: error: expected 2 array elements; found 1\n",
1960 "{}",1960 "{}",
1961 .{status},1961 .{diag},
1962 );1962 );
1963 }1963 }
19641964
1965 // Expect 3 find 01965 // Expect 3 find 0
1966 {1966 {
1967 var status: Status = .{};1967 var diag: Diagnostics = .{};
1968 defer status.deinit(gpa);1968 defer diag.deinit(gpa);
1969 try std.testing.expectError(1969 try std.testing.expectError(
1970 error.ParseZon,1970 error.ParseZon,
1971 fromSlice([3]u8, gpa, ".{}", &status, .{}),1971 fromSlice([3]u8, gpa, ".{}", &diag, .{}),
1972 );1972 );
1973 try std.testing.expectFmt(1973 try std.testing.expectFmt(
1974 "1:2: error: expected 3 array elements; found 0\n",1974 "1:2: error: expected 3 array elements; found 0\n",
1975 "{}",1975 "{}",
1976 .{status},1976 .{diag},
1977 );1977 );
1978 }1978 }
19791979
...@@ -1981,24 +1981,24 @@ test "std.zon arrays and slices" {...@@ -1981,24 +1981,24 @@ test "std.zon arrays and slices" {
1981 {1981 {
1982 // Array1982 // Array
1983 {1983 {
1984 var status: Status = .{};1984 var diag: Diagnostics = .{};
1985 defer status.deinit(gpa);1985 defer diag.deinit(gpa);
1986 try std.testing.expectError(1986 try std.testing.expectError(
1987 error.ParseZon,1987 error.ParseZon,
1988 fromSlice([3]bool, gpa, ".{'a', 'b', 'c'}", &status, .{}),1988 fromSlice([3]bool, gpa, ".{'a', 'b', 'c'}", &diag, .{}),
1989 );1989 );
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});
1991 }1991 }
19921992
1993 // Slice1993 // Slice
1994 {1994 {
1995 var status: Status = .{};1995 var diag: Diagnostics = .{};
1996 defer status.deinit(gpa);1996 defer diag.deinit(gpa);
1997 try std.testing.expectError(1997 try std.testing.expectError(
1998 error.ParseZon,1998 error.ParseZon,
1999 fromSlice([]bool, gpa, ".{'a', 'b', 'c'}", &status, .{}),1999 fromSlice([]bool, gpa, ".{'a', 'b', 'c'}", &diag, .{}),
2000 );2000 );
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});
2002 }2002 }
2003 }2003 }
20042004
...@@ -2006,39 +2006,39 @@ test "std.zon arrays and slices" {...@@ -2006,39 +2006,39 @@ test "std.zon arrays and slices" {
2006 {2006 {
2007 // Array2007 // Array
2008 {2008 {
2009 var status: Status = .{};2009 var diag: Diagnostics = .{};
2010 defer status.deinit(gpa);2010 defer diag.deinit(gpa);
2011 try std.testing.expectError(2011 try std.testing.expectError(
2012 error.ParseZon,2012 error.ParseZon,
2013 fromSlice([3]u8, gpa, "'a'", &status, .{}),2013 fromSlice([3]u8, gpa, "'a'", &diag, .{}),
2014 );2014 );
2015 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2015 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2016 }2016 }
20172017
2018 // Slice2018 // Slice
2019 {2019 {
2020 var status: Status = .{};2020 var diag: Diagnostics = .{};
2021 defer status.deinit(gpa);2021 defer diag.deinit(gpa);
2022 try std.testing.expectError(2022 try std.testing.expectError(
2023 error.ParseZon,2023 error.ParseZon,
2024 fromSlice([]u8, gpa, "'a'", &status, .{}),2024 fromSlice([]u8, gpa, "'a'", &diag, .{}),
2025 );2025 );
2026 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2026 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2027 }2027 }
2028 }2028 }
20292029
2030 // Address of is not allowed (indirection for slices in ZON is implicit)2030 // Address of is not allowed (indirection for slices in ZON is implicit)
2031 {2031 {
2032 var status: Status = .{};2032 var diag: Diagnostics = .{};
2033 defer status.deinit(gpa);2033 defer diag.deinit(gpa);
2034 try std.testing.expectError(2034 try std.testing.expectError(
2035 error.ParseZon,2035 error.ParseZon,
2036 fromSlice([]u8, gpa, " &.{'a', 'b', 'c'}", &status, .{}),2036 fromSlice([]u8, gpa, " &.{'a', 'b', 'c'}", &diag, .{}),
2037 );2037 );
2038 try std.testing.expectFmt(2038 try std.testing.expectFmt(
2039 "1:3: error: pointers are not available in ZON\n",2039 "1:3: error: pointers are not available in ZON\n",
2040 "{}",2040 "{}",
2041 .{status},2041 .{diag},
2042 );2042 );
2043 }2043 }
2044}2044}
...@@ -2070,23 +2070,23 @@ test "std.zon string literal" {...@@ -2070,23 +2070,23 @@ test "std.zon string literal" {
2070 // Passing string literal to a mutable slice2070 // Passing string literal to a mutable slice
2071 {2071 {
2072 {2072 {
2073 var status: Status = .{};2073 var diag: Diagnostics = .{};
2074 defer status.deinit(gpa);2074 defer diag.deinit(gpa);
2075 try std.testing.expectError(2075 try std.testing.expectError(
2076 error.ParseZon,2076 error.ParseZon,
2077 fromSlice([]u8, gpa, "\"abcd\"", &status, .{}),2077 fromSlice([]u8, gpa, "\"abcd\"", &diag, .{}),
2078 );2078 );
2079 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2079 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2080 }2080 }
20812081
2082 {2082 {
2083 var status: Status = .{};2083 var diag: Diagnostics = .{};
2084 defer status.deinit(gpa);2084 defer diag.deinit(gpa);
2085 try std.testing.expectError(2085 try std.testing.expectError(
2086 error.ParseZon,2086 error.ParseZon,
2087 fromSlice([]u8, gpa, "\\\\abcd", &status, .{}),2087 fromSlice([]u8, gpa, "\\\\abcd", &diag, .{}),
2088 );2088 );
2089 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2089 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2090 }2090 }
2091 }2091 }
20922092
...@@ -2097,23 +2097,23 @@ test "std.zon string literal" {...@@ -2097,23 +2097,23 @@ test "std.zon string literal" {
2097 defer ast.deinit(gpa);2097 defer ast.deinit(gpa);
2098 var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false });2098 var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false });
2099 defer zoir.deinit(gpa);2099 defer zoir.deinit(gpa);
2100 var status: Status = .{};2100 var diag: Diagnostics = .{};
2101 defer status.deinit(gpa);2101 defer diag.deinit(gpa);
2102 try std.testing.expectError(2102 try std.testing.expectError(
2103 error.ParseZon,2103 error.ParseZon,
2104 fromSlice([4:0]u8, gpa, "\"abcd\"", &status, .{}),2104 fromSlice([4:0]u8, gpa, "\"abcd\"", &diag, .{}),
2105 );2105 );
2106 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2106 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2107 }2107 }
21082108
2109 {2109 {
2110 var status: Status = .{};2110 var diag: Diagnostics = .{};
2111 defer status.deinit(gpa);2111 defer diag.deinit(gpa);
2112 try std.testing.expectError(2112 try std.testing.expectError(
2113 error.ParseZon,2113 error.ParseZon,
2114 fromSlice([4:0]u8, gpa, "\\\\abcd", &status, .{}),2114 fromSlice([4:0]u8, gpa, "\\\\abcd", &diag, .{}),
2115 );2115 );
2116 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2116 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2117 }2117 }
2118 }2118 }
21192119
...@@ -2149,102 +2149,102 @@ test "std.zon string literal" {...@@ -2149,102 +2149,102 @@ test "std.zon string literal" {
2149 // Other value terminated slices2149 // Other value terminated slices
2150 {2150 {
2151 {2151 {
2152 var status: Status = .{};2152 var diag: Diagnostics = .{};
2153 defer status.deinit(gpa);2153 defer diag.deinit(gpa);
2154 try std.testing.expectError(2154 try std.testing.expectError(
2155 error.ParseZon,2155 error.ParseZon,
2156 fromSlice([:1]const u8, gpa, "\"foo\"", &status, .{}),2156 fromSlice([:1]const u8, gpa, "\"foo\"", &diag, .{}),
2157 );2157 );
2158 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2158 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2159 }2159 }
21602160
2161 {2161 {
2162 var status: Status = .{};2162 var diag: Diagnostics = .{};
2163 defer status.deinit(gpa);2163 defer diag.deinit(gpa);
2164 try std.testing.expectError(2164 try std.testing.expectError(
2165 error.ParseZon,2165 error.ParseZon,
2166 fromSlice([:1]const u8, gpa, "\\\\foo", &status, .{}),2166 fromSlice([:1]const u8, gpa, "\\\\foo", &diag, .{}),
2167 );2167 );
2168 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2168 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2169 }2169 }
2170 }2170 }
21712171
2172 // Expecting string literal, getting something else2172 // Expecting string literal, getting something else
2173 {2173 {
2174 var status: Status = .{};2174 var diag: Diagnostics = .{};
2175 defer status.deinit(gpa);2175 defer diag.deinit(gpa);
2176 try std.testing.expectError(2176 try std.testing.expectError(
2177 error.ParseZon,2177 error.ParseZon,
2178 fromSlice([]const u8, gpa, "true", &status, .{}),2178 fromSlice([]const u8, gpa, "true", &diag, .{}),
2179 );2179 );
2180 try std.testing.expectFmt("1:1: error: expected string\n", "{}", .{status});2180 try std.testing.expectFmt("1:1: error: expected string\n", "{}", .{diag});
2181 }2181 }
21822182
2183 // Expecting string literal, getting an incompatible tuple2183 // Expecting string literal, getting an incompatible tuple
2184 {2184 {
2185 var status: Status = .{};2185 var diag: Diagnostics = .{};
2186 defer status.deinit(gpa);2186 defer diag.deinit(gpa);
2187 try std.testing.expectError(2187 try std.testing.expectError(
2188 error.ParseZon,2188 error.ParseZon,
2189 fromSlice([]const u8, gpa, ".{false}", &status, .{}),2189 fromSlice([]const u8, gpa, ".{false}", &diag, .{}),
2190 );2190 );
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});
2192 }2192 }
21932193
2194 // Invalid string literal2194 // Invalid string literal
2195 {2195 {
2196 var status: Status = .{};2196 var diag: Diagnostics = .{};
2197 defer status.deinit(gpa);2197 defer diag.deinit(gpa);
2198 try std.testing.expectError(2198 try std.testing.expectError(
2199 error.ParseZon,2199 error.ParseZon,
2200 fromSlice([]const i8, gpa, "\"\\a\"", &status, .{}),2200 fromSlice([]const i8, gpa, "\"\\a\"", &diag, .{}),
2201 );2201 );
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});
2203 }2203 }
22042204
2205 // Slice wrong child type2205 // Slice wrong child type
2206 {2206 {
2207 {2207 {
2208 var status: Status = .{};2208 var diag: Diagnostics = .{};
2209 defer status.deinit(gpa);2209 defer diag.deinit(gpa);
2210 try std.testing.expectError(2210 try std.testing.expectError(
2211 error.ParseZon,2211 error.ParseZon,
2212 fromSlice([]const i8, gpa, "\"a\"", &status, .{}),2212 fromSlice([]const i8, gpa, "\"a\"", &diag, .{}),
2213 );2213 );
2214 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2214 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2215 }2215 }
22162216
2217 {2217 {
2218 var status: Status = .{};2218 var diag: Diagnostics = .{};
2219 defer status.deinit(gpa);2219 defer diag.deinit(gpa);
2220 try std.testing.expectError(2220 try std.testing.expectError(
2221 error.ParseZon,2221 error.ParseZon,
2222 fromSlice([]const i8, gpa, "\\\\a", &status, .{}),2222 fromSlice([]const i8, gpa, "\\\\a", &diag, .{}),
2223 );2223 );
2224 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2224 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2225 }2225 }
2226 }2226 }
22272227
2228 // Bad alignment2228 // Bad alignment
2229 {2229 {
2230 {2230 {
2231 var status: Status = .{};2231 var diag: Diagnostics = .{};
2232 defer status.deinit(gpa);2232 defer diag.deinit(gpa);
2233 try std.testing.expectError(2233 try std.testing.expectError(
2234 error.ParseZon,2234 error.ParseZon,
2235 fromSlice([]align(2) const u8, gpa, "\"abc\"", &status, .{}),2235 fromSlice([]align(2) const u8, gpa, "\"abc\"", &diag, .{}),
2236 );2236 );
2237 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2237 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2238 }2238 }
22392239
2240 {2240 {
2241 var status: Status = .{};2241 var diag: Diagnostics = .{};
2242 defer status.deinit(gpa);2242 defer diag.deinit(gpa);
2243 try std.testing.expectError(2243 try std.testing.expectError(
2244 error.ParseZon,2244 error.ParseZon,
2245 fromSlice([]align(2) const u8, gpa, "\\\\abc", &status, .{}),2245 fromSlice([]align(2) const u8, gpa, "\\\\abc", &diag, .{}),
2246 );2246 );
2247 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{status});2247 try std.testing.expectFmt("1:1: error: expected array\n", "{}", .{diag});
2248 }2248 }
2249 }2249 }
22502250
...@@ -2307,11 +2307,11 @@ test "std.zon enum literals" {...@@ -2307,11 +2307,11 @@ test "std.zon enum literals" {
23072307
2308 // Bad tag2308 // Bad tag
2309 {2309 {
2310 var status: Status = .{};2310 var diag: Diagnostics = .{};
2311 defer status.deinit(gpa);2311 defer diag.deinit(gpa);
2312 try std.testing.expectError(2312 try std.testing.expectError(
2313 error.ParseZon,2313 error.ParseZon,
2314 fromSlice(Enum, gpa, ".qux", &status, .{}),2314 fromSlice(Enum, gpa, ".qux", &diag, .{}),
2315 );2315 );
2316 try std.testing.expectFmt(2316 try std.testing.expectFmt(
2317 \\1:2: error: unexpected enum literal 'qux'2317 \\1:2: error: unexpected enum literal 'qux'
...@@ -2319,17 +2319,17 @@ test "std.zon enum literals" {...@@ -2319,17 +2319,17 @@ test "std.zon enum literals" {
2319 \\2319 \\
2320 ,2320 ,
2321 "{}",2321 "{}",
2322 .{status},2322 .{diag},
2323 );2323 );
2324 }2324 }
23252325
2326 // Bad tag that's too long for parser2326 // Bad tag that's too long for parser
2327 {2327 {
2328 var status: Status = .{};2328 var diag: Diagnostics = .{};
2329 defer status.deinit(gpa);2329 defer diag.deinit(gpa);
2330 try std.testing.expectError(2330 try std.testing.expectError(
2331 error.ParseZon,2331 error.ParseZon,
2332 fromSlice(Enum, gpa, ".@\"foobarbaz\"", &status, .{}),2332 fromSlice(Enum, gpa, ".@\"foobarbaz\"", &diag, .{}),
2333 );2333 );
2334 try std.testing.expectFmt(2334 try std.testing.expectFmt(
2335 \\1:2: error: unexpected enum literal 'foobarbaz'2335 \\1:2: error: unexpected enum literal 'foobarbaz'
...@@ -2337,33 +2337,33 @@ test "std.zon enum literals" {...@@ -2337,33 +2337,33 @@ test "std.zon enum literals" {
2337 \\2337 \\
2338 ,2338 ,
2339 "{}",2339 "{}",
2340 .{status},2340 .{diag},
2341 );2341 );
2342 }2342 }
23432343
2344 // Bad type2344 // Bad type
2345 {2345 {
2346 var status: Status = .{};2346 var diag: Diagnostics = .{};
2347 defer status.deinit(gpa);2347 defer diag.deinit(gpa);
2348 try std.testing.expectError(2348 try std.testing.expectError(
2349 error.ParseZon,2349 error.ParseZon,
2350 fromSlice(Enum, gpa, "true", &status, .{}),2350 fromSlice(Enum, gpa, "true", &diag, .{}),
2351 );2351 );
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});
2353 }2353 }
23542354
2355 // Test embedded nulls in an identifier2355 // Test embedded nulls in an identifier
2356 {2356 {
2357 var status: Status = .{};2357 var diag: Diagnostics = .{};
2358 defer status.deinit(gpa);2358 defer diag.deinit(gpa);
2359 try std.testing.expectError(2359 try std.testing.expectError(
2360 error.ParseZon,2360 error.ParseZon,
2361 fromSlice(Enum, gpa, ".@\"\\x00\"", &status, .{}),2361 fromSlice(Enum, gpa, ".@\"\\x00\"", &diag, .{}),
2362 );2362 );
2363 try std.testing.expectFmt(2363 try std.testing.expectFmt(
2364 "1:2: error: identifier cannot contain null bytes\n",2364 "1:2: error: identifier cannot contain null bytes\n",
2365 "{}",2365 "{}",
2366 .{status},2366 .{diag},
2367 );2367 );
2368 }2368 }
2369}2369}
...@@ -2377,24 +2377,24 @@ test "std.zon parse bool" {...@@ -2377,24 +2377,24 @@ test "std.zon parse bool" {
23772377
2378 // Errors2378 // Errors
2379 {2379 {
2380 var status: Status = .{};2380 var diag: Diagnostics = .{};
2381 defer status.deinit(gpa);2381 defer diag.deinit(gpa);
2382 try std.testing.expectError(2382 try std.testing.expectError(
2383 error.ParseZon,2383 error.ParseZon,
2384 fromSlice(bool, gpa, " foo", &status, .{}),2384 fromSlice(bool, gpa, " foo", &diag, .{}),
2385 );2385 );
2386 try std.testing.expectFmt(2386 try std.testing.expectFmt(
2387 \\1:2: error: invalid expression2387 \\1:2: error: invalid expression
2388 \\1:2: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'2388 \\1:2: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
2389 \\1:2: note: precede identifier with '.' for an enum literal2389 \\1:2: note: precede identifier with '.' for an enum literal
2390 \\2390 \\
2391 , "{}", .{status});2391 , "{}", .{diag});
2392 }2392 }
2393 {2393 {
2394 var status: Status = .{};2394 var diag: Diagnostics = .{};
2395 defer status.deinit(gpa);2395 defer diag.deinit(gpa);
2396 try std.testing.expectError(error.ParseZon, fromSlice(bool, gpa, "123", &status, .{}));2396 try std.testing.expectError(error.ParseZon, fromSlice(bool, gpa, "123", &diag, .{}));
2397 try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{}", .{status});2397 try std.testing.expectFmt("1:1: error: expected type 'bool'\n", "{}", .{diag});
2398 }2398 }
2399}2399}
24002400
...@@ -2456,35 +2456,35 @@ test "std.zon parse int" {...@@ -2456,35 +2456,35 @@ test "std.zon parse int" {
2456 try fromSlice(i66, gpa, "-36893488147419103232", null, .{}),2456 try fromSlice(i66, gpa, "-36893488147419103232", null, .{}),
2457 );2457 );
2458 {2458 {
2459 var status: Status = .{};2459 var diag: Diagnostics = .{};
2460 defer status.deinit(gpa);2460 defer diag.deinit(gpa);
2461 try std.testing.expectError(error.ParseZon, fromSlice(2461 try std.testing.expectError(error.ParseZon, fromSlice(
2462 i66,2462 i66,
2463 gpa,2463 gpa,
2464 "36893488147419103232",2464 "36893488147419103232",
2465 &status,2465 &diag,
2466 .{},2466 .{},
2467 ));2467 ));
2468 try std.testing.expectFmt(2468 try std.testing.expectFmt(
2469 "1:1: error: type 'i66' cannot represent value\n",2469 "1:1: error: type 'i66' cannot represent value\n",
2470 "{}",2470 "{}",
2471 .{status},2471 .{diag},
2472 );2472 );
2473 }2473 }
2474 {2474 {
2475 var status: Status = .{};2475 var diag: Diagnostics = .{};
2476 defer status.deinit(gpa);2476 defer diag.deinit(gpa);
2477 try std.testing.expectError(error.ParseZon, fromSlice(2477 try std.testing.expectError(error.ParseZon, fromSlice(
2478 i66,2478 i66,
2479 gpa,2479 gpa,
2480 "-36893488147419103233",2480 "-36893488147419103233",
2481 &status,2481 &diag,
2482 .{},2482 .{},
2483 ));2483 ));
2484 try std.testing.expectFmt(2484 try std.testing.expectFmt(
2485 "1:1: error: type 'i66' cannot represent value\n",2485 "1:1: error: type 'i66' cannot represent value\n",
2486 "{}",2486 "{}",
2487 .{status},2487 .{diag},
2488 );2488 );
2489 }2489 }
24902490
...@@ -2567,108 +2567,108 @@ test "std.zon parse int" {...@@ -2567,108 +2567,108 @@ test "std.zon parse int" {
25672567
2568 // Number with invalid character in the middle2568 // Number with invalid character in the middle
2569 {2569 {
2570 var status: Status = .{};2570 var diag: Diagnostics = .{};
2571 defer status.deinit(gpa);2571 defer diag.deinit(gpa);
2572 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "32a32", &status, .{}));2572 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "32a32", &diag, .{}));
2573 try std.testing.expectFmt(2573 try std.testing.expectFmt(
2574 "1:3: error: invalid digit 'a' for decimal base\n",2574 "1:3: error: invalid digit 'a' for decimal base\n",
2575 "{}",2575 "{}",
2576 .{status},2576 .{diag},
2577 );2577 );
2578 }2578 }
25792579
2580 // Failing to parse as int2580 // Failing to parse as int
2581 {2581 {
2582 var status: Status = .{};2582 var diag: Diagnostics = .{};
2583 defer status.deinit(gpa);2583 defer diag.deinit(gpa);
2584 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "true", &status, .{}));2584 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "true", &diag, .{}));
2585 try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{}", .{status});2585 try std.testing.expectFmt("1:1: error: expected type 'u8'\n", "{}", .{diag});
2586 }2586 }
25872587
2588 // Failing because an int is out of range2588 // Failing because an int is out of range
2589 {2589 {
2590 var status: Status = .{};2590 var diag: Diagnostics = .{};
2591 defer status.deinit(gpa);2591 defer diag.deinit(gpa);
2592 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "256", &status, .{}));2592 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "256", &diag, .{}));
2593 try std.testing.expectFmt(2593 try std.testing.expectFmt(
2594 "1:1: error: type 'u8' cannot represent value\n",2594 "1:1: error: type 'u8' cannot represent value\n",
2595 "{}",2595 "{}",
2596 .{status},2596 .{diag},
2597 );2597 );
2598 }2598 }
25992599
2600 // Failing because a negative int is out of range2600 // Failing because a negative int is out of range
2601 {2601 {
2602 var status: Status = .{};2602 var diag: Diagnostics = .{};
2603 defer status.deinit(gpa);2603 defer diag.deinit(gpa);
2604 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-129", &status, .{}));2604 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-129", &diag, .{}));
2605 try std.testing.expectFmt(2605 try std.testing.expectFmt(
2606 "1:1: error: type 'i8' cannot represent value\n",2606 "1:1: error: type 'i8' cannot represent value\n",
2607 "{}",2607 "{}",
2608 .{status},2608 .{diag},
2609 );2609 );
2610 }2610 }
26112611
2612 // Failing because an unsigned int is negative2612 // Failing because an unsigned int is negative
2613 {2613 {
2614 var status: Status = .{};2614 var diag: Diagnostics = .{};
2615 defer status.deinit(gpa);2615 defer diag.deinit(gpa);
2616 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1", &status, .{}));2616 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1", &diag, .{}));
2617 try std.testing.expectFmt(2617 try std.testing.expectFmt(
2618 "1:1: error: type 'u8' cannot represent value\n",2618 "1:1: error: type 'u8' cannot represent value\n",
2619 "{}",2619 "{}",
2620 .{status},2620 .{diag},
2621 );2621 );
2622 }2622 }
26232623
2624 // Failing because a float is non-whole2624 // Failing because a float is non-whole
2625 {2625 {
2626 var status: Status = .{};2626 var diag: Diagnostics = .{};
2627 defer status.deinit(gpa);2627 defer diag.deinit(gpa);
2628 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "1.5", &status, .{}));2628 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "1.5", &diag, .{}));
2629 try std.testing.expectFmt(2629 try std.testing.expectFmt(
2630 "1:1: error: type 'u8' cannot represent value\n",2630 "1:1: error: type 'u8' cannot represent value\n",
2631 "{}",2631 "{}",
2632 .{status},2632 .{diag},
2633 );2633 );
2634 }2634 }
26352635
2636 // Failing because a float is negative2636 // Failing because a float is negative
2637 {2637 {
2638 var status: Status = .{};2638 var diag: Diagnostics = .{};
2639 defer status.deinit(gpa);2639 defer diag.deinit(gpa);
2640 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1.0", &status, .{}));2640 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "-1.0", &diag, .{}));
2641 try std.testing.expectFmt(2641 try std.testing.expectFmt(
2642 "1:1: error: type 'u8' cannot represent value\n",2642 "1:1: error: type 'u8' cannot represent value\n",
2643 "{}",2643 "{}",
2644 .{status},2644 .{diag},
2645 );2645 );
2646 }2646 }
26472647
2648 // Negative integer zero2648 // Negative integer zero
2649 {2649 {
2650 var status: Status = .{};2650 var diag: Diagnostics = .{};
2651 defer status.deinit(gpa);2651 defer diag.deinit(gpa);
2652 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-0", &status, .{}));2652 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-0", &diag, .{}));
2653 try std.testing.expectFmt(2653 try std.testing.expectFmt(
2654 \\1:2: error: integer literal '-0' is ambiguous2654 \\1:2: error: integer literal '-0' is ambiguous
2655 \\1:2: note: use '0' for an integer zero2655 \\1:2: note: use '0' for an integer zero
2656 \\1:2: note: use '-0.0' for a floating-point signed zero2656 \\1:2: note: use '-0.0' for a floating-point signed zero
2657 \\2657 \\
2658 , "{}", .{status});2658 , "{}", .{diag});
2659 }2659 }
26602660
2661 // Negative integer zero casted to float2661 // Negative integer zero casted to float
2662 {2662 {
2663 var status: Status = .{};2663 var diag: Diagnostics = .{};
2664 defer status.deinit(gpa);2664 defer diag.deinit(gpa);
2665 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-0", &status, .{}));2665 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-0", &diag, .{}));
2666 try std.testing.expectFmt(2666 try std.testing.expectFmt(
2667 \\1:2: error: integer literal '-0' is ambiguous2667 \\1:2: error: integer literal '-0' is ambiguous
2668 \\1:2: note: use '0' for an integer zero2668 \\1:2: note: use '0' for an integer zero
2669 \\1:2: note: use '-0.0' for a floating-point signed zero2669 \\1:2: note: use '-0.0' for a floating-point signed zero
2670 \\2670 \\
2671 , "{}", .{status});2671 , "{}", .{diag});
2672 }2672 }
26732673
2674 // Negative float 0 is allowed2674 // Negative float 0 is allowed
...@@ -2679,48 +2679,48 @@ test "std.zon parse int" {...@@ -2679,48 +2679,48 @@ test "std.zon parse int" {
26792679
2680 // Double negation is not allowed2680 // Double negation is not allowed
2681 {2681 {
2682 var status: Status = .{};2682 var diag: Diagnostics = .{};
2683 defer status.deinit(gpa);2683 defer diag.deinit(gpa);
2684 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "--2", &status, .{}));2684 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "--2", &diag, .{}));
2685 try std.testing.expectFmt(2685 try std.testing.expectFmt(
2686 "1:1: error: expected number or 'inf' after '-'\n",2686 "1:1: error: expected number or 'inf' after '-'\n",
2687 "{}",2687 "{}",
2688 .{status},2688 .{diag},
2689 );2689 );
2690 }2690 }
26912691
2692 {2692 {
2693 var status: Status = .{};2693 var diag: Diagnostics = .{};
2694 defer status.deinit(gpa);2694 defer diag.deinit(gpa);
2695 try std.testing.expectError(2695 try std.testing.expectError(
2696 error.ParseZon,2696 error.ParseZon,
2697 fromSlice(f32, gpa, "--2.0", &status, .{}),2697 fromSlice(f32, gpa, "--2.0", &diag, .{}),
2698 );2698 );
2699 try std.testing.expectFmt(2699 try std.testing.expectFmt(
2700 "1:1: error: expected number or 'inf' after '-'\n",2700 "1:1: error: expected number or 'inf' after '-'\n",
2701 "{}",2701 "{}",
2702 .{status},2702 .{diag},
2703 );2703 );
2704 }2704 }
27052705
2706 // Invalid int literal2706 // Invalid int literal
2707 {2707 {
2708 var status: Status = .{};2708 var diag: Diagnostics = .{};
2709 defer status.deinit(gpa);2709 defer diag.deinit(gpa);
2710 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0xg", &status, .{}));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", "{}", .{status});2711 try std.testing.expectFmt("1:3: error: invalid digit 'g' for hex base\n", "{}", .{diag});
2712 }2712 }
27132713
2714 // Notes on invalid int literal2714 // Notes on invalid int literal
2715 {2715 {
2716 var status: Status = .{};2716 var diag: Diagnostics = .{};
2717 defer status.deinit(gpa);2717 defer diag.deinit(gpa);
2718 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0123", &status, .{}));2718 try std.testing.expectError(error.ParseZon, fromSlice(u8, gpa, "0123", &diag, .{}));
2719 try std.testing.expectFmt(2719 try std.testing.expectFmt(
2720 \\1:1: error: number '0123' has leading zero2720 \\1:1: error: number '0123' has leading zero
2721 \\1:1: note: use '0o' prefix for octal literals2721 \\1:1: note: use '0o' prefix for octal literals
2722 \\2722 \\
2723 , "{}", .{status});2723 , "{}", .{diag});
2724 }2724 }
2725}2725}
27262726
...@@ -2728,23 +2728,23 @@ test "std.zon negative char" {...@@ -2728,23 +2728,23 @@ test "std.zon negative char" {
2728 const gpa = std.testing.allocator;2728 const gpa = std.testing.allocator;
27292729
2730 {2730 {
2731 var status: Status = .{};2731 var diag: Diagnostics = .{};
2732 defer status.deinit(gpa);2732 defer diag.deinit(gpa);
2733 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-'a'", &status, .{}));2733 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-'a'", &diag, .{}));
2734 try std.testing.expectFmt(2734 try std.testing.expectFmt(
2735 "1:1: error: expected number or 'inf' after '-'\n",2735 "1:1: error: expected number or 'inf' after '-'\n",
2736 "{}",2736 "{}",
2737 .{status},2737 .{diag},
2738 );2738 );
2739 }2739 }
2740 {2740 {
2741 var status: Status = .{};2741 var diag: Diagnostics = .{};
2742 defer status.deinit(gpa);2742 defer diag.deinit(gpa);
2743 try std.testing.expectError(error.ParseZon, fromSlice(i16, gpa, "-'a'", &status, .{}));2743 try std.testing.expectError(error.ParseZon, fromSlice(i16, gpa, "-'a'", &diag, .{}));
2744 try std.testing.expectFmt(2744 try std.testing.expectFmt(
2745 "1:1: error: expected number or 'inf' after '-'\n",2745 "1:1: error: expected number or 'inf' after '-'\n",
2746 "{}",2746 "{}",
2747 .{status},2747 .{diag},
2748 );2748 );
2749 }2749 }
2750}2750}
...@@ -2825,81 +2825,81 @@ test "std.zon parse float" {...@@ -2825,81 +2825,81 @@ test "std.zon parse float" {
28252825
2826 // Negative nan not allowed2826 // Negative nan not allowed
2827 {2827 {
2828 var status: Status = .{};2828 var diag: Diagnostics = .{};
2829 defer status.deinit(gpa);2829 defer diag.deinit(gpa);
2830 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-nan", &status, .{}));2830 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-nan", &diag, .{}));
2831 try std.testing.expectFmt(2831 try std.testing.expectFmt(
2832 "1:1: error: expected number or 'inf' after '-'\n",2832 "1:1: error: expected number or 'inf' after '-'\n",
2833 "{}",2833 "{}",
2834 .{status},2834 .{diag},
2835 );2835 );
2836 }2836 }
28372837
2838 // nan as int not allowed2838 // nan as int not allowed
2839 {2839 {
2840 var status: Status = .{};2840 var diag: Diagnostics = .{};
2841 defer status.deinit(gpa);2841 defer diag.deinit(gpa);
2842 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &status, .{}));2842 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &diag, .{}));
2843 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status});2843 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag});
2844 }2844 }
28452845
2846 // nan as int not allowed2846 // nan as int not allowed
2847 {2847 {
2848 var status: Status = .{};2848 var diag: Diagnostics = .{};
2849 defer status.deinit(gpa);2849 defer diag.deinit(gpa);
2850 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &status, .{}));2850 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "nan", &diag, .{}));
2851 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status});2851 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag});
2852 }2852 }
28532853
2854 // inf as int not allowed2854 // inf as int not allowed
2855 {2855 {
2856 var status: Status = .{};2856 var diag: Diagnostics = .{};
2857 defer status.deinit(gpa);2857 defer diag.deinit(gpa);
2858 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "inf", &status, .{}));2858 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "inf", &diag, .{}));
2859 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status});2859 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag});
2860 }2860 }
28612861
2862 // -inf as int not allowed2862 // -inf as int not allowed
2863 {2863 {
2864 var status: Status = .{};2864 var diag: Diagnostics = .{};
2865 defer status.deinit(gpa);2865 defer diag.deinit(gpa);
2866 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-inf", &status, .{}));2866 try std.testing.expectError(error.ParseZon, fromSlice(i8, gpa, "-inf", &diag, .{}));
2867 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{status});2867 try std.testing.expectFmt("1:1: error: expected type 'i8'\n", "{}", .{diag});
2868 }2868 }
28692869
2870 // Bad identifier as float2870 // Bad identifier as float
2871 {2871 {
2872 var status: Status = .{};2872 var diag: Diagnostics = .{};
2873 defer status.deinit(gpa);2873 defer diag.deinit(gpa);
2874 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "foo", &status, .{}));2874 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "foo", &diag, .{}));
2875 try std.testing.expectFmt(2875 try std.testing.expectFmt(
2876 \\1:1: error: invalid expression2876 \\1:1: error: invalid expression
2877 \\1:1: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'2877 \\1:1: note: ZON allows identifiers 'true', 'false', 'null', 'inf', and 'nan'
2878 \\1:1: note: precede identifier with '.' for an enum literal2878 \\1:1: note: precede identifier with '.' for an enum literal
2879 \\2879 \\
2880 , "{}", .{status});2880 , "{}", .{diag});
2881 }2881 }
28822882
2883 {2883 {
2884 var status: Status = .{};2884 var diag: Diagnostics = .{};
2885 defer status.deinit(gpa);2885 defer diag.deinit(gpa);
2886 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-foo", &status, .{}));2886 try std.testing.expectError(error.ParseZon, fromSlice(f32, gpa, "-foo", &diag, .{}));
2887 try std.testing.expectFmt(2887 try std.testing.expectFmt(
2888 "1:1: error: expected number or 'inf' after '-'\n",2888 "1:1: error: expected number or 'inf' after '-'\n",
2889 "{}",2889 "{}",
2890 .{status},2890 .{diag},
2891 );2891 );
2892 }2892 }
28932893
2894 // Non float as float2894 // Non float as float
2895 {2895 {
2896 var status: Status = .{};2896 var diag: Diagnostics = .{};
2897 defer status.deinit(gpa);2897 defer diag.deinit(gpa);
2898 try std.testing.expectError(2898 try std.testing.expectError(
2899 error.ParseZon,2899 error.ParseZon,
2900 fromSlice(f32, gpa, "\"foo\"", &status, .{}),2900 fromSlice(f32, gpa, "\"foo\"", &diag, .{}),
2901 );2901 );
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});
2903 }2903 }
2904}2904}
29052905
...@@ -3136,69 +3136,69 @@ test "std.zon vector" {...@@ -3136,69 +3136,69 @@ test "std.zon vector" {
31363136
3137 // Too few fields3137 // Too few fields
3138 {3138 {
3139 var status: Status = .{};3139 var diag: Diagnostics = .{};
3140 defer status.deinit(gpa);3140 defer diag.deinit(gpa);
3141 try std.testing.expectError(3141 try std.testing.expectError(
3142 error.ParseZon,3142 error.ParseZon,
3143 fromSlice(@Vector(2, f32), gpa, ".{0.5}", &status, .{}),3143 fromSlice(@Vector(2, f32), gpa, ".{0.5}", &diag, .{}),
3144 );3144 );
3145 try std.testing.expectFmt(3145 try std.testing.expectFmt(
3146 "1:2: error: expected 2 vector elements; found 1\n",3146 "1:2: error: expected 2 vector elements; found 1\n",
3147 "{}",3147 "{}",
3148 .{status},3148 .{diag},
3149 );3149 );
3150 }3150 }
31513151
3152 // Too many fields3152 // Too many fields
3153 {3153 {
3154 var status: Status = .{};3154 var diag: Diagnostics = .{};
3155 defer status.deinit(gpa);3155 defer diag.deinit(gpa);
3156 try std.testing.expectError(3156 try std.testing.expectError(
3157 error.ParseZon,3157 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, .{}),
3159 );3159 );
3160 try std.testing.expectFmt(3160 try std.testing.expectFmt(
3161 "1:2: error: expected 2 vector elements; found 3\n",3161 "1:2: error: expected 2 vector elements; found 3\n",
3162 "{}",3162 "{}",
3163 .{status},3163 .{diag},
3164 );3164 );
3165 }3165 }
31663166
3167 // Wrong type fields3167 // Wrong type fields
3168 {3168 {
3169 var status: Status = .{};3169 var diag: Diagnostics = .{};
3170 defer status.deinit(gpa);3170 defer diag.deinit(gpa);
3171 try std.testing.expectError(3171 try std.testing.expectError(
3172 error.ParseZon,3172 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, .{}),
3174 );3174 );
3175 try std.testing.expectFmt(3175 try std.testing.expectFmt(
3176 "1:8: error: expected type 'f32'\n",3176 "1:8: error: expected type 'f32'\n",
3177 "{}",3177 "{}",
3178 .{status},3178 .{diag},
3179 );3179 );
3180 }3180 }
31813181
3182 // Wrong type3182 // Wrong type
3183 {3183 {
3184 var status: Status = .{};3184 var diag: Diagnostics = .{};
3185 defer status.deinit(gpa);3185 defer diag.deinit(gpa);
3186 try std.testing.expectError(3186 try std.testing.expectError(
3187 error.ParseZon,3187 error.ParseZon,
3188 fromSlice(@Vector(3, u8), gpa, "true", &status, .{}),3188 fromSlice(@Vector(3, u8), gpa, "true", &diag, .{}),
3189 );3189 );
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});
3191 }3191 }
31923192
3193 // Elements should get freed on error3193 // Elements should get freed on error
3194 {3194 {
3195 var status: Status = .{};3195 var diag: Diagnostics = .{};
3196 defer status.deinit(gpa);3196 defer diag.deinit(gpa);
3197 try std.testing.expectError(3197 try std.testing.expectError(
3198 error.ParseZon,3198 error.ParseZon,
3199 fromSlice(@Vector(3, *u8), gpa, ".{1, true, 3}", &status, .{}),3199 fromSlice(@Vector(3, *u8), gpa, ".{1, true, 3}", &diag, .{}),
3200 );3200 );
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});
3202 }3202 }
3203}3203}
32043204
...@@ -3316,133 +3316,133 @@ test "std.zon add pointers" {...@@ -3316,133 +3316,133 @@ test "std.zon add pointers" {
33163316
3317 // Test that optional types are flattened correctly in errors3317 // Test that optional types are flattened correctly in errors
3318 {3318 {
3319 var status: Status = .{};3319 var diag: Diagnostics = .{};
3320 defer status.deinit(gpa);3320 defer diag.deinit(gpa);
3321 try std.testing.expectError(3321 try std.testing.expectError(
3322 error.ParseZon,3322 error.ParseZon,
3323 fromSlice(*const ?*const u8, gpa, "true", &status, .{}),3323 fromSlice(*const ?*const u8, gpa, "true", &diag, .{}),
3324 );3324 );
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});
3326 }3326 }
33273327
3328 {3328 {
3329 var status: Status = .{};3329 var diag: Diagnostics = .{};
3330 defer status.deinit(gpa);3330 defer diag.deinit(gpa);
3331 try std.testing.expectError(3331 try std.testing.expectError(
3332 error.ParseZon,3332 error.ParseZon,
3333 fromSlice(*const ?*const f32, gpa, "true", &status, .{}),3333 fromSlice(*const ?*const f32, gpa, "true", &diag, .{}),
3334 );3334 );
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});
3336 }3336 }
33373337
3338 {3338 {
3339 var status: Status = .{};3339 var diag: Diagnostics = .{};
3340 defer status.deinit(gpa);3340 defer diag.deinit(gpa);
3341 try std.testing.expectError(3341 try std.testing.expectError(
3342 error.ParseZon,3342 error.ParseZon,
3343 fromSlice(*const ?*const @Vector(3, u8), gpa, "true", &status, .{}),3343 fromSlice(*const ?*const @Vector(3, u8), gpa, "true", &diag, .{}),
3344 );3344 );
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});
3346 }3346 }
33473347
3348 {3348 {
3349 var status: Status = .{};3349 var diag: Diagnostics = .{};
3350 defer status.deinit(gpa);3350 defer diag.deinit(gpa);
3351 try std.testing.expectError(3351 try std.testing.expectError(
3352 error.ParseZon,3352 error.ParseZon,
3353 fromSlice(*const ?*const bool, gpa, "10", &status, .{}),3353 fromSlice(*const ?*const bool, gpa, "10", &diag, .{}),
3354 );3354 );
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});
3356 }3356 }
33573357
3358 {3358 {
3359 var status: Status = .{};3359 var diag: Diagnostics = .{};
3360 defer status.deinit(gpa);3360 defer diag.deinit(gpa);
3361 try std.testing.expectError(3361 try std.testing.expectError(
3362 error.ParseZon,3362 error.ParseZon,
3363 fromSlice(*const ?*const struct { a: i32 }, gpa, "true", &status, .{}),3363 fromSlice(*const ?*const struct { a: i32 }, gpa, "true", &diag, .{}),
3364 );3364 );
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});
3366 }3366 }
33673367
3368 {3368 {
3369 var status: Status = .{};3369 var diag: Diagnostics = .{};
3370 defer status.deinit(gpa);3370 defer diag.deinit(gpa);
3371 try std.testing.expectError(3371 try std.testing.expectError(
3372 error.ParseZon,3372 error.ParseZon,
3373 fromSlice(*const ?*const struct { i32 }, gpa, "true", &status, .{}),3373 fromSlice(*const ?*const struct { i32 }, gpa, "true", &diag, .{}),
3374 );3374 );
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});
3376 }3376 }
33773377
3378 {3378 {
3379 var status: Status = .{};3379 var diag: Diagnostics = .{};
3380 defer status.deinit(gpa);3380 defer diag.deinit(gpa);
3381 try std.testing.expectError(3381 try std.testing.expectError(
3382 error.ParseZon,3382 error.ParseZon,
3383 fromSlice(*const ?*const union { x: void }, gpa, "true", &status, .{}),3383 fromSlice(*const ?*const union { x: void }, gpa, "true", &diag, .{}),
3384 );3384 );
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});
3386 }3386 }
33873387
3388 {3388 {
3389 var status: Status = .{};3389 var diag: Diagnostics = .{};
3390 defer status.deinit(gpa);3390 defer diag.deinit(gpa);
3391 try std.testing.expectError(3391 try std.testing.expectError(
3392 error.ParseZon,3392 error.ParseZon,
3393 fromSlice(*const ?*const [3]u8, gpa, "true", &status, .{}),3393 fromSlice(*const ?*const [3]u8, gpa, "true", &diag, .{}),
3394 );3394 );
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});
3396 }3396 }
33973397
3398 {3398 {
3399 var status: Status = .{};3399 var diag: Diagnostics = .{};
3400 defer status.deinit(gpa);3400 defer diag.deinit(gpa);
3401 try std.testing.expectError(3401 try std.testing.expectError(
3402 error.ParseZon,3402 error.ParseZon,
3403 fromSlice(?[3]u8, gpa, "true", &status, .{}),3403 fromSlice(?[3]u8, gpa, "true", &diag, .{}),
3404 );3404 );
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});
3406 }3406 }
34073407
3408 {3408 {
3409 var status: Status = .{};3409 var diag: Diagnostics = .{};
3410 defer status.deinit(gpa);3410 defer diag.deinit(gpa);
3411 try std.testing.expectError(3411 try std.testing.expectError(
3412 error.ParseZon,3412 error.ParseZon,
3413 fromSlice(*const ?*const []u8, gpa, "true", &status, .{}),3413 fromSlice(*const ?*const []u8, gpa, "true", &diag, .{}),
3414 );3414 );
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});
3416 }3416 }
34173417
3418 {3418 {
3419 var status: Status = .{};3419 var diag: Diagnostics = .{};
3420 defer status.deinit(gpa);3420 defer diag.deinit(gpa);
3421 try std.testing.expectError(3421 try std.testing.expectError(
3422 error.ParseZon,3422 error.ParseZon,
3423 fromSlice(?[]u8, gpa, "true", &status, .{}),3423 fromSlice(?[]u8, gpa, "true", &diag, .{}),
3424 );3424 );
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});
3426 }3426 }
34273427
3428 {3428 {
3429 var status: Status = .{};3429 var diag: Diagnostics = .{};
3430 defer status.deinit(gpa);3430 defer diag.deinit(gpa);
3431 try std.testing.expectError(3431 try std.testing.expectError(
3432 error.ParseZon,3432 error.ParseZon,
3433 fromSlice(*const ?*const []const u8, gpa, "true", &status, .{}),3433 fromSlice(*const ?*const []const u8, gpa, "true", &diag, .{}),
3434 );3434 );
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});
3436 }3436 }
34373437
3438 {3438 {
3439 var status: Status = .{};3439 var diag: Diagnostics = .{};
3440 defer status.deinit(gpa);3440 defer diag.deinit(gpa);
3441 try std.testing.expectError(3441 try std.testing.expectError(
3442 error.ParseZon,3442 error.ParseZon,
3443 fromSlice(*const ?*const enum { foo }, gpa, "true", &status, .{}),3443 fromSlice(*const ?*const enum { foo }, gpa, "true", &diag, .{}),
3444 );3444 );
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});
3446 }3446 }
3447}3447}
34483448
...@@ -3455,17 +3455,17 @@ test "std.zon stop on node" {...@@ -3455,17 +3455,17 @@ test "std.zon stop on node" {
3455 y: f32,3455 y: f32,
3456 };3456 };
34573457
3458 var status: Status = .{};3458 var diag: Diagnostics = .{};
3459 defer status.deinit(gpa);3459 defer diag.deinit(gpa);
3460 const result = try fromSlice(Vec2, gpa, ".{ .x = 1.5, .y = 2.5 }", &status, .{});3460 const result = try fromSlice(Vec2, gpa, ".{ .x = 1.5, .y = 2.5 }", &diag, .{});
3461 try std.testing.expectEqual(result.y, 2.5);3461 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.?));
3463 }3463 }
34643464
3465 {3465 {
3466 var status: Status = .{};3466 var diag: Diagnostics = .{};
3467 defer status.deinit(gpa);3467 defer diag.deinit(gpa);
3468 const result = try fromSlice(Zoir.Node.Index, gpa, "1.23", &status, .{});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(status.zoir.?));3469 try std.testing.expectEqual(Zoir.Node{ .float_literal = 1.23 }, result.get(diag.zoir.?));
3470 }3470 }
3471}3471}