Skip to content

Commit 7077e90

Browse files
nektroVexu
authored andcommitted
std.meta: allow ArgsTuple to be used on functions with comptime parameters
any comptime parameter sets `.is_generic` to be true but in many cases these will still be discrete types available in `.params`
1 parent ccfb0d4 commit 7077e90

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/std/meta.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,14 +1037,12 @@ pub fn ArgsTuple(comptime Function: type) type {
10371037
@compileError("ArgsTuple expects a function type");
10381038

10391039
const function_info = info.Fn;
1040-
if (function_info.is_generic)
1041-
@compileError("Cannot create ArgsTuple for generic function");
10421040
if (function_info.is_var_args)
10431041
@compileError("Cannot create ArgsTuple for variadic function");
10441042

10451043
var argument_field_list: [function_info.params.len]type = undefined;
10461044
inline for (function_info.params, 0..) |arg, i| {
1047-
const T = arg.type.?;
1045+
const T = arg.type orelse @compileError("cannot create ArgsTuple for function with an 'anytype' parameter");
10481046
argument_field_list[i] = T;
10491047
}
10501048

@@ -1116,6 +1114,7 @@ test "ArgsTuple" {
11161114
TupleTester.assertTuple(.{u32}, ArgsTuple(fn (a: u32) []const u8));
11171115
TupleTester.assertTuple(.{ u32, f16 }, ArgsTuple(fn (a: u32, b: f16) noreturn));
11181116
TupleTester.assertTuple(.{ u32, f16, []const u8, void }, ArgsTuple(fn (a: u32, b: f16, c: []const u8, void) noreturn));
1117+
TupleTester.assertTuple(.{u32}, ArgsTuple(fn (comptime a: u32) []const u8));
11191118
}
11201119

11211120
test "Tuple" {

0 commit comments

Comments
 (0)