authorgravatar for xq@random-projects.netFelix "xq" Queißner <xq@random-projects.net> 2020-10-02 09:37:01+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-17 21:10:01-04:00
logb014bc77c8c5b89a8c0b5d4a995726ec6b350939
tree1f010a6e43b877d89c2890499d4090f27d57ba98
parent2a256d5ea02c8f520c54fd335c38891d6e05a63f

Fixes std.meta.Tuple and std.meta.ArgsTuple for zero-sized types (like void).


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

lib/std/meta.zig+7-6
......@@ -846,14 +846,15 @@ pub fn ArgsTuple(comptime Function: type) type {
846846
847847 var argument_field_list: [function_info.args.len]std.builtin.TypeInfo.StructField = undefined;
848848 inline for (function_info.args) |arg, i| {
849 const T = arg.arg_type.?;
849850 @setEvalBranchQuota(10_000);
850851 var num_buf: [128]u8 = undefined;
851852 argument_field_list[i] = std.builtin.TypeInfo.StructField{
852853 .name = std.fmt.bufPrint(&num_buf, "{d}", .{i}) catch unreachable,
853 .field_type = arg.arg_type.?,
854 .default_value = @as(?(arg.arg_type.?), null),
854 .field_type = T,
855 .default_value = @as(?T, null),
855856 .is_comptime = false,
856 .alignment = @alignOf(arg.arg_type.?),
857 .alignment = if (@sizeOf(T) > 0) @alignOf(T) else 0,
857858 };
858859 }
859860
......@@ -884,7 +885,7 @@ pub fn Tuple(comptime types: []const type) type {
884885 .field_type = T,
885886 .default_value = @as(?T, null),
886887 .is_comptime = false,
887 .alignment = @alignOf(T),
888 .alignment = if (@sizeOf(T) > 0) @alignOf(T) else 0,
888889 };
889890 }
890891
......@@ -927,12 +928,12 @@ test "ArgsTuple" {
927928 TupleTester.assertTuple(.{}, ArgsTuple(fn () void));
928929 TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8));
929930 TupleTester.assertTuple(.{ u32, f16 }, ArgsTuple(fn (a: u32, b: f16) noreturn));
930 TupleTester.assertTuple(.{ u32, f16, []const u8 }, ArgsTuple(fn (a: u32, b: f16, c: []const u8) noreturn));
931 TupleTester.assertTuple(.{ u32, f16, []const u8, void }, ArgsTuple(fn (a: u32, b: f16, c: []const u8, void) noreturn));
931932}
932933
933934test "Tuple" {
934935 TupleTester.assertTuple(.{}, Tuple(&[_]type{}));
935936 TupleTester.assertTuple(.{u32}, Tuple(&[_]type{u32}));
936937 TupleTester.assertTuple(.{ u32, f16 }, Tuple(&[_]type{ u32, f16 }));
937 TupleTester.assertTuple(.{ u32, f16, []const u8 }, Tuple(&[_]type{ u32, f16, []const u8 }));
938 TupleTester.assertTuple(.{ u32, f16, []const u8, void }, Tuple(&[_]type{ u32, f16, []const u8, void }));
938939}