Skip to content

Compile error when trying to load a ZON file with an enum literal member #23280

@dk949

Description

@dk949

Zig Version

0.14.0

Steps to Reproduce and Observed Behavior

Compile the following file:

const std = @import("std");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const alloc = gpa.allocator();
    defer _ = gpa.deinit();

    const ZonType = struct {
        comptime field: @TypeOf(.value) = .value,
    };
    const zon_txt =
        \\.{
        \\    .field = .value,
        \\}
    ;

    const zon_parsed = try std.zon.parse.fromSlice(ZonType, alloc, zon_txt, null, .{});
    defer std.zon.parse.free(alloc, zon_parsed);
}

Observed behaviour

Compiler reaches unreachable code in a switch in std.zon.parse.free.

This also happens if I delete the call to std.zon.parse.free.

Expected Behavior

Program compiles with no error.

Parsing a ZON file with enum literals is required to fully read a build.zig.zon file.

(It's still possible to read it partially by using the ignore_unknown_fields option when parsing)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions