authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-04 12:49:17 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-04 12:49:17 -07:00
log29587071de6dd3338e8eb76d4e0307af69a2d61a
treee7e49273047a0ca0fb1ae649fc0fc0fc7620103d
parent7025bfa226566b84347680c600ad7d416ba51917

put the errorCast use in its own function

see zig#20177 for more info

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

json.zig+5-2
......@@ -27,8 +27,7 @@ pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype, options:
2727 std.debug.assert(try p.addArray(alloc, &.{}) == .empty_array);
2828 std.debug.assert(try p.addObject(alloc, &ObjectHashMap{}) == .empty_object);
2929
30 const root_err: (@TypeOf(inreader).Error || Error)!ValueIndex = @errorCast(parseElement(alloc, &p));
31 const root = try root_err;
30 const root = try parseElementPrecise(alloc, &p, @TypeOf(inreader).Error || Error);
3231 if (p.avail() > 0) return error.MalformedJson;
3332 const data = try p.parser.data.toOwnedSlice(alloc);
3433
......@@ -38,6 +37,10 @@ pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype, options:
3837 };
3938}
4039
40fn parseElementPrecise(alloc: std.mem.Allocator, p: *Parser, comptime E: type) E!ValueIndex {
41 return @errorCast(parseElement(alloc, p));
42}
43
4144fn parseElement(alloc: std.mem.Allocator, p: *Parser) anyerror!ValueIndex {
4245 const t = tracer.trace(@src(), "", .{});
4346 defer t.end();