diff --git a/src/value.zig b/src/value.zig index 839b3d7580..96242331f9 100644 --- a/src/value.zig +++ b/src/value.zig @@ -1072,11 +1072,13 @@ pub const Value = extern union { .enum_simple => Module.EnumFull.ValueMap{}, else => unreachable, }; - break :field_index if (values.entries.len == 0) + if (values.entries.len == 0) { // auto-numbered enum - @intCast(u32, val.toUnsignedInt(mod.getTarget())) - else - @intCast(u32, values.getIndexContext(val, .{ .ty = ty, .mod = mod }).?); + break :field_index @intCast(u32, val.toUnsignedInt(mod.getTarget())); + } + var buffer: Type.Payload.Bits = undefined; + const int_tag_ty = ty.intTagType(&buffer); + break :field_index @intCast(u32, values.getIndexContext(val, .{ .ty = int_tag_ty, .mod = mod }).?); }, }; diff --git a/test/behavior/call.zig b/test/behavior/call.zig index 4d8f22d15f..a8d0d40751 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -344,3 +344,28 @@ test "inline call doesn't re-evaluate non generic struct" { try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); comptime try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); } + +test "Enum constructed by @Type passed as generic argument" { + const S = struct { + const E = std.meta.FieldEnum(struct { + prev_pos: bool, + pos: bool, + vel: bool, + damp_vel: bool, + acc: bool, + rgba: bool, + prev_scale: bool, + scale: bool, + prev_rotation: bool, + rotation: bool, + angular_vel: bool, + alive: bool, + }); + fn foo(comptime a: E, b: u32) !void { + try expect(@enumToInt(a) == b); + } + }; + inline for (@typeInfo(S.E).Enum.fields) |_, i| { + try S.foo(@intToEnum(S.E, i), i); + } +}