Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explicitly specify error set of std.json.stringify #16323

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/std/json/stringify.zig
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub fn stringify(
value: anytype,
options: StringifyOptions,
out_stream: anytype,
) !void {
) @TypeOf(out_stream).Error!void {
const T = @TypeOf(value);
switch (@typeInfo(T)) {
.Float, .ComptimeFloat => {
Expand Down
17 changes: 0 additions & 17 deletions lib/std/json/stringify_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,6 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions
if (vos.expected_remaining.len > 0) return error.NotEnoughData;
}

test "stringify struct with custom stringify that returns a custom error" {
var ret = stringify(struct {
field: Field = .{},

pub const Field = struct {
field: ?[]*Field = null,

const Self = @This();
pub fn jsonStringify(_: Self, _: StringifyOptions, _: anytype) error{CustomError}!void {
return error.CustomError;
}
};
}{}, StringifyOptions{}, std.io.null_writer);

try std.testing.expectError(error.CustomError, ret);
}

test "stringify alloc" {
const allocator = std.testing.allocator;
const expected =
Expand Down