authorgravatar for techatrix@mailbox.orgTechatrix <techatrix@mailbox.org> 2023-07-04 21:10:39+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-10 10:50:57-07:00
log3bf0b8eada9ec97d4413fed5be29f5e2af30dce1
treeabb28345bbfebf4e87a77156b94bb2426da8533d
parent2b8c1f0d4619565255b9faff2d24bc2360012552

explicitly specify error set of `std.json.stringify`


2 files changed, 1 insertions(+), 18 deletions(-)

lib/std/json/stringify.zig+1-1
......@@ -140,7 +140,7 @@ pub fn stringify(
140140 value: anytype,
141141 options: StringifyOptions,
142142 out_stream: anytype,
143) !void {
143) @TypeOf(out_stream).Error!void {
144144 const T = @TypeOf(value);
145145 switch (@typeInfo(T)) {
146146 .Float, .ComptimeFloat => {
lib/std/json/stringify_test.zig-17
......@@ -260,23 +260,6 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions
260260 if (vos.expected_remaining.len > 0) return error.NotEnoughData;
261261}
262262
263test "stringify struct with custom stringify that returns a custom error" {
264 var ret = stringify(struct {
265 field: Field = .{},
266
267 pub const Field = struct {
268 field: ?[]*Field = null,
269
270 const Self = @This();
271 pub fn jsonStringify(_: Self, _: StringifyOptions, _: anytype) error{CustomError}!void {
272 return error.CustomError;
273 }
274 };
275 }{}, StringifyOptions{}, std.io.null_writer);
276
277 try std.testing.expectError(error.CustomError, ret);
278}
279
280263test "stringify alloc" {
281264 const allocator = std.testing.allocator;
282265 const expected =