Skip to content

Handle parsing into ambiguous types in a union #18

@LewisGaul

Description

@LewisGaul

As reported in https://zigforum.org/t/zig-nestedtext-release-0-1-0/383/17:

test "typed parse: jeang3nie" {
    const Kind = union(enum) {
        color: []const u8,
        plain,
    };
    var p = Parser.init(testing.allocator, .{});
    const r = try p.parseTyped(Kind, "> null");
    defer p.parseTypedFree(r);
    std.debug.print("{s}\n", .{r});
}

This parses into color with the string null since this is the first field that succeeds, but parsing as a string should probably be the last resort (since this will always succeed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions