| author | |
| committer | |
| log | 22d46e1d7753ea2a9accc180e8613206120739c5 |
| tree | a416ddd2e321e1012a624dd81a13b36804a34bf9 |
| parent | 2926d95e6a7c4d83eb197f78de40718e97bc1f1b |
Closes #137572 files changed, 31 insertions(+), 4 deletions(-)
src/value.zig+6-4| ... | @@ -1072,11 +1072,13 @@ pub const Value = extern union { | ... | @@ -1072,11 +1072,13 @@ pub const Value = extern union { |
| 1072 | .enum_simple => Module.EnumFull.ValueMap{}, | 1072 | .enum_simple => Module.EnumFull.ValueMap{}, |
| 1073 | else => unreachable, | 1073 | else => unreachable, |
| 1074 | }; | 1074 | }; |
| 1075 | break :field_index if (values.entries.len == 0) | 1075 | if (values.entries.len == 0) { |
| 1076 | // auto-numbered enum | 1076 | // auto-numbered enum |
| 1077 | @intCast(u32, val.toUnsignedInt(mod.getTarget())) | 1077 | break :field_index @intCast(u32, val.toUnsignedInt(mod.getTarget())); |
| 1078 | else | 1078 | } |
| 1079 | @intCast(u32, values.getIndexContext(val, .{ .ty = ty, .mod = mod }).?); | 1079 | var buffer: Type.Payload.Bits = undefined; |
| 1080 | const int_tag_ty = ty.intTagType(&buffer); | ||
| 1081 | break :field_index @intCast(u32, values.getIndexContext(val, .{ .ty = int_tag_ty, .mod = mod }).?); | ||
| 1080 | }, | 1082 | }, |
| 1081 | }; | 1083 | }; |
| 1082 | 1084 |
test/behavior/call.zig+25| ... | @@ -344,3 +344,28 @@ test "inline call doesn't re-evaluate non generic struct" { | ... | @@ -344,3 +344,28 @@ test "inline call doesn't re-evaluate non generic struct" { |
| 344 | try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); | 344 | try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); |
| 345 | comptime try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); | 345 | comptime try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); |
| 346 | } | 346 | } |
| 347 | |||
| 348 | test "Enum constructed by @Type passed as generic argument" { | ||
| 349 | const S = struct { | ||
| 350 | const E = std.meta.FieldEnum(struct { | ||
| 351 | prev_pos: bool, | ||
| 352 | pos: bool, | ||
| 353 | vel: bool, | ||
| 354 | damp_vel: bool, | ||
| 355 | acc: bool, | ||
| 356 | rgba: bool, | ||
| 357 | prev_scale: bool, | ||
| 358 | scale: bool, | ||
| 359 | prev_rotation: bool, | ||
| 360 | rotation: bool, | ||
| 361 | angular_vel: bool, | ||
| 362 | alive: bool, | ||
| 363 | }); | ||
| 364 | fn foo(comptime a: E, b: u32) !void { | ||
| 365 | try expect(@enumToInt(a) == b); | ||
| 366 | } | ||
| 367 | }; | ||
| 368 | inline for (@typeInfo(S.E).Enum.fields) |_, i| { | ||
| 369 | try S.foo(@intToEnum(S.E, i), i); | ||
| 370 | } | ||
| 371 | } |