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

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

Open
NicoElbers opened this issue Feb 17, 2025 · 0 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved.

Comments

@NicoElbers
Copy link
Contributor

NicoElbers commented Feb 17, 2025

Zig Version

0.14.0-dev.3213+53216d2f2

Steps to Reproduce and Observed Output

mwe.zig

const Foo = struct {
    foo: ?union(enum) { b },
};

pub fn main() !void {
    const stdout = std.io.getStdOut();
    const writer = stdout.writer();

    const foo: Foo = .{ .foo = .b };

    try std.zon.stringify.serialize(foo, .{}, writer);
}

const std = @import("std");

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

Observe:

/nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/debug.zig:518:14: error: reached unreachable code
    if (!ok) unreachable; // assertion failure
             ^~~~~~~~~~~
/nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:493:28: note: called from here
            comptime assert(canSerializeType(@TypeOf(val)));
                     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    fieldArbitraryDepth__anon_19074: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:1005:56
    fieldArbitraryDepth__anon_18003: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:907:55
    valueArbitraryDepth__anon_16985: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:584:83
    valueArbitraryDepth__anon_14342: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:593:49
    fieldArbitraryDepth__anon_10402: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:1005:56
    fieldArbitraryDepth__anon_7688: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:907:55
    valueArbitraryDepth__anon_5065: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:571:62
    value__anon_2935: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:473:44
    serialize__anon_1989: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/zon/stringify.zig:51:17
    main: mwe.zig:11:36
    posixCallMainAndExit: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/start.zig:656:37
    _start: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/start.zig:464:40
    comptime: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/start.zig:91:63
    start: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/lib/std/std.zig:97:27
    comptime: /nix/store/w0x7fxnl703niapxdabvwjhbpmcrz5b5-zig-0.14.0-dev.3237+ddff1fa4c/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.

@NicoElbers NicoElbers added the error message This issue points out an error message that is unhelpful and should be improved. label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

1 participant