authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-09 22:54:39 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-09 22:54:39 -07:00
log409601d50a476784d3872763077c816e53505d0a
tree4593265f2e67687d08d09501d87b4f6bfdd934c7
parentd9eb60881bf215d41ed75b3429817809c37ec76c
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add union support in ifequal


1 files changed, 7 insertions(+), 0 deletions(-)

src/lib.zig+7
...@@ -250,12 +250,19 @@ fn doInner(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Val...@@ -250,12 +250,19 @@ fn doInner(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Val
250 .ifequal => {250 .ifequal => {
251 comptime assertEqual(v.args.len, 2);251 comptime assertEqual(v.args.len, 2);
252 const y = try resolveArg(v.args[1], alloc, data, ctx, opts);252 const y = try resolveArg(v.args[1], alloc, data, ctx, opts);
253 const Y = @TypeOf(y);
253 if (@typeInfo(@TypeOf(x)) == .@"enum" and comptime extras.isZigString(@TypeOf(y))) {254 if (@typeInfo(@TypeOf(x)) == .@"enum" and comptime extras.isZigString(@TypeOf(y))) {
254 return try doif(alloc, writer, body, bottom, data, ctx, opts, std.mem.eql(u8, @tagName(x), y));255 return try doif(alloc, writer, body, bottom, data, ctx, opts, std.mem.eql(u8, @tagName(x), y));
255 }256 }
256 if (TI == .@"enum" and @typeInfo(@TypeOf(y)) == .int) {257 if (TI == .@"enum" and @typeInfo(@TypeOf(y)) == .int) {
257 return doif(alloc, writer, body, bottom, data, ctx, opts, @intFromEnum(x) == y);258 return doif(alloc, writer, body, bottom, data, ctx, opts, @intFromEnum(x) == y);
258 }259 }
260 if (TI == .@"union" and comptime extras.isZigString(Y)) {
261 const tag = std.meta.stringToEnum(TI.@"union".tag_type.?, y) orelse {
262 return doif(alloc, writer, body, bottom, data, ctx, opts, false);
263 };
264 return doif(alloc, writer, body, bottom, data, ctx, opts, x == tag);
265 }
259 if (comptime extras.isSlice(@TypeOf(x, y))) {266 if (comptime extras.isSlice(@TypeOf(x, y))) {
260 return try doif(alloc, writer, body, bottom, data, ctx, opts, std.mem.eql(u8, x, y));267 return try doif(alloc, writer, body, bottom, data, ctx, opts, std.mem.eql(u8, x, y));
261 }268 }