From 409601d50a476784d3872763077c816e53505d0a Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sat, 9 May 2026 22:54:39 -0700 Subject: [PATCH] add union support in ifequal --- src/lib.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib.zig b/src/lib.zig index 64837fa45a593201399db7e886ba033a68dd486d..07e00aaf664b3ed032f4c8801c8f816abcfd10fb 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -250,12 +250,19 @@ fn doInner(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Val .ifequal => { comptime assertEqual(v.args.len, 2); const y = try resolveArg(v.args[1], alloc, data, ctx, opts); + const Y = @TypeOf(y); if (@typeInfo(@TypeOf(x)) == .@"enum" and comptime extras.isZigString(@TypeOf(y))) { return try doif(alloc, writer, body, bottom, data, ctx, opts, std.mem.eql(u8, @tagName(x), y)); } if (TI == .@"enum" and @typeInfo(@TypeOf(y)) == .int) { return doif(alloc, writer, body, bottom, data, ctx, opts, @intFromEnum(x) == y); } + if (TI == .@"union" and comptime extras.isZigString(Y)) { + const tag = std.meta.stringToEnum(TI.@"union".tag_type.?, y) orelse { + return doif(alloc, writer, body, bottom, data, ctx, opts, false); + }; + return doif(alloc, writer, body, bottom, data, ctx, opts, x == tag); + } if (comptime extras.isSlice(@TypeOf(x, y))) { return try doif(alloc, writer, body, bottom, data, ctx, opts, std.mem.eql(u8, x, y)); } -- 2.54.0