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 {...@@ -846,14 +846,15 @@ pub fn ArgsTuple(comptime Function: type) type {
846846
847 var argument_field_list: [function_info.args.len]std.builtin.TypeInfo.StructField = undefined;847 var argument_field_list: [function_info.args.len]std.builtin.TypeInfo.StructField = undefined;
848 inline for (function_info.args) |arg, i| {848 inline for (function_info.args) |arg, i| {
849 const T = arg.arg_type.?;
849 @setEvalBranchQuota(10_000);850 @setEvalBranchQuota(10_000);
850 var num_buf: [128]u8 = undefined;851 var num_buf: [128]u8 = undefined;
851 argument_field_list[i] = std.builtin.TypeInfo.StructField{852 argument_field_list[i] = std.builtin.TypeInfo.StructField{
852 .name = std.fmt.bufPrint(&num_buf, "{d}", .{i}) catch unreachable,853 .name = std.fmt.bufPrint(&num_buf, "{d}", .{i}) catch unreachable,
853 .field_type = arg.arg_type.?,854 .field_type = T,
854 .default_value = @as(?(arg.arg_type.?), null),855 .default_value = @as(?T, null),
855 .is_comptime = false,856 .is_comptime = false,
856 .alignment = @alignOf(arg.arg_type.?),857 .alignment = if (@sizeOf(T) > 0) @alignOf(T) else 0,
857 };858 };
858 }859 }
859860
...@@ -884,7 +885,7 @@ pub fn Tuple(comptime types: []const type) type {...@@ -884,7 +885,7 @@ pub fn Tuple(comptime types: []const type) type {
884 .field_type = T,885 .field_type = T,
885 .default_value = @as(?T, null),886 .default_value = @as(?T, null),
886 .is_comptime = false,887 .is_comptime = false,
887 .alignment = @alignOf(T),888 .alignment = if (@sizeOf(T) > 0) @alignOf(T) else 0,
888 };889 };
889 }890 }
890891
...@@ -927,12 +928,12 @@ test "ArgsTuple" {...@@ -927,12 +928,12 @@ test "ArgsTuple" {
927 TupleTester.assertTuple(.{}, ArgsTuple(fn () void));928 TupleTester.assertTuple(.{}, ArgsTuple(fn () void));
928 TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8));929 TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8));
929 TupleTester.assertTuple(.{ u32, f16 }, ArgsTuple(fn (a: u32, b: f16) noreturn));930 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));
931}932}
932933
933test "Tuple" {934test "Tuple" {
934 TupleTester.assertTuple(.{}, Tuple(&[_]type{}));935 TupleTester.assertTuple(.{}, Tuple(&[_]type{}));
935 TupleTester.assertTuple(.{u32}, Tuple(&[_]type{u32}));936 TupleTester.assertTuple(.{u32}, Tuple(&[_]type{u32}));
936 TupleTester.assertTuple(.{ u32, f16 }, Tuple(&[_]type{ u32, f16 }));937 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 }));
938}939}