#String to Enum error with union(enum)

1 messages · Page 1 of 1 (latest)

keen oak
#

Getting the following error

/home/sattva/Git/zig-linux-x86_64-0.14.0-dev.1472+3929cac15/lib/std/meta.zig:24:21: error: access of union field 'enum' while field 'union' is active
    if (@typeInfo(T).@"enum".fields.len <= 100) {
        ~~~~~~~~~~~~^~~~~~~~
/home/sattva/Git/zig-linux-x86_64-0.14.0-dev.1472+3929cac15/lib/std/builtin.zig:257:18: note: union declared here
pub const Type = union(enum) {

trying to use the meta method:

        // Conver Simobject enum to a string for lookup
        const str_enum = std.meta.stringToEnum(sim.SimObject, obj_name) orelse {
            errdefer std.log.err("Object [{s}] was unable to be created, is it a valid SimObject?", .{obj_name});
            return errors.JsonMissingGroup;
        };


        // Init specific objects, as a sim object interface
        switch (str_enum) {
     ect....
sweet python
#

i think the error is relatively self explanatory?

#

you're trying to use stringToEnum on a union, which is not an enum

keen oak
#

For sure, I guess the better question is.... how can I access the enum from the union for this purpose

sweet python
#

you can a union's tag type using std.meta.Tag(sim.SimObject)

#

or just @typeInfo(sim.SimObject).@"union".tag_type

keen oak
#

oh sick that worked thanks!