mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
parent
2926d95e6a
commit
22d46e1d77
@ -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 }).?);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user