Skip to content

Commit b014bc7

Browse files
ikskuhandrewrk
authored andcommitted
Fixes std.meta.Tuple and std.meta.ArgsTuple for zero-sized types (like void).
1 parent 2a256d5 commit b014bc7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/std/meta.zig

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

933934
test "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
}

0 commit comments

Comments
 (0)