Zig Version
0.10.0-dev.1335+c64279b15
Steps to Reproduce
The test program is below: Note:
- The
switch return type is required for the function sig.
- The
switch return value is required for the function body.
- The function call is required
- If you wrap the whole test in a
comptime {} block it works.
const std = @import("std");
const Type = std.builtin.Type;
test "Tuple" {
const fields_list = fields(@TypeOf(.{}));
if (fields_list.len != 0)
@compileError("Argument count mismatch");
}
pub fn fields(comptime T: type) switch (@typeInfo(T)) {
.Struct => []const Type.StructField,
else => unreachable,
} {
return switch (@typeInfo(T)) {
.Struct => |info| info.fields,
else => unreachable,
};
}
Expected Behavior
Should not have any errors (stage1 works), since fields.len should be comptime known.
The reason: this is how std.meta tests Tuple and ArgsTuple, so this is exercised in the stdlib.
Actual Behavior
Triggers @compileError
Zig Version
0.10.0-dev.1335+c64279b15
Steps to Reproduce
The test program is below: Note:
switchreturn type is required for the function sig.switchreturn value is required for the function body.comptime {}block it works.Expected Behavior
Should not have any errors (stage1 works), since
fields.lenshould be comptime known.The reason: this is how
std.metatestsTupleandArgsTuple, so this is exercised in the stdlib.Actual Behavior
Triggers
@compileError