Can I activate union tag in generic union from inline switch else case?

I have two generic tagged union and one generic enum, and there’s my code:

const  Tag = enum { ... };
const  Config = union(Tag) { ... };
const  Module = union(Tag) { ... };

const Complete = @This();

module: Module;

pub fn init(config: Config) Complete {
    return switch (config) {
        inline else => |i, tag| {
            var mod: Module = undefined;

            // I've tried setting exactly the field, but that didn't helped.
            // @field(mod, @tagName(tag)) = undefined;

            // The tag isn't active so it fails.
            @field(mod, @tagName(tag)).config = i;

            return .{ .module = mod };
        },
    };
}

How can I activate tag in union to write it? The Module and Config is generic union created at comptime, Tag is enum, that also created at comptime.

Try const mod = @unionInit(Module, @tagName(tag), i);

2 Likes

It works. I don’t know how I missed it in the documentation…