Skip to content

zon: canSerializeType provides no information as to what it cannot serialize #22919

@NicoElbers

Description

@NicoElbers

Zig Version

0.14.0-dev.3213+53216d2f2

Steps to Reproduce and Observed Output

mwe.zig

pub const Foo = struct {
    bar: struct {
        baz: void, // Illegal here
    } = .{ .baz = {} },
};

pub fn main() !void {
    var arr = std.ArrayList(u8).init(std.heap.smp_allocator);
    defer arr.deinit();

    try std.zon.stringify.serialize(@as(Foo, .{}), .{}, arr.writer());
}
const std = @import("std");

run zig build-exe -freference-trace mwe.zig

Observe:

/nix/store/4h7cpfzzsczh6g8ivdvaz5k9dygy5z6p-zig-0.14.0-dev.3241+55c46870b/lib/std/debug.zig:518:14: error: reached unreachable code
    if (!ok) unreachable; // assertion failure
             ^~~~~~~~~~~
/nix/store/4h7cpfzzsczh6g8ivdvaz5k9dygy5z6p-zig-0.14.0-dev.3241+55c46870b/lib/std/zon/stringify.zig:493:28: note: called from here
            comptime assert(canSerializeType(@TypeOf(val)));
                     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    value__anon_3073: /nix/store/4h7cpfzzsczh6g8ivdvaz5k9dygy5z6p-zig-0.14.0-dev.3241+55c46870b/lib/std/zon/stringify.zig:473:44
    serialize__anon_2007: /nix/store/4h7cpfzzsczh6g8ivdvaz5k9dygy5z6p-zig-0.14.0-dev.3241+55c46870b/lib/std/zon/stringify.zig:51:17
    main: mwe.zig:11:36
    posixCallMainAndExit: /nix/store/4h7cpfzzsczh6g8ivdvaz5k9dygy5z6p-zig-0.14.0-dev.3241+55c46870b/lib/std/start.zig:656:37
    _start: /nix/store/4h7cpfzzsczh6g8ivdvaz5k9dygy5z6p-zig-0.14.0-dev.3241+55c46870b/lib/std/start.zig:464:40
    comptime: /nix/store/4h7cpfzzsczh6g8ivdvaz5k9dygy5z6p-zig-0.14.0-dev.3241+55c46870b/lib/std/start.zig:91:63
    start: /nix/store/4h7cpfzzsczh6g8ivdvaz5k9dygy5z6p-zig-0.14.0-dev.3241+55c46870b/lib/std/std.zig:97:27
    comptime: /nix/store/4h7cpfzzsczh6g8ivdvaz5k9dygy5z6p-zig-0.14.0-dev.3241+55c46870b/lib/std/std.zig:168:9

Expected Output

I expect canSerializeType to fail in a spot that shows me why I cannot serialize this type, or otherwise provides more detail what exactly cannot be serialized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions