mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
std.testing: add refAllDeclsRecursive function
This commit is contained in:
parent
43770c0103
commit
9c66fdadc7
@ -723,3 +723,19 @@ pub fn refAllDecls(comptime T: type) void {
|
||||
if (decl.is_pub) _ = @field(T, decl.name);
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a type, and Recursively reference all the declarations inside, so that the semantic analyzer sees them.
|
||||
/// For deep types, you may use `@setEvalBranchQuota`
|
||||
pub fn refAllDeclsRecursive(comptime T: type) void {
|
||||
inline for (comptime std.meta.declarations(T)) |decl| {
|
||||
if (decl.is_pub) {
|
||||
if (@TypeOf(@field(T, decl.name)) == type) {
|
||||
switch (@typeInfo(@field(T, decl.name))) {
|
||||
.Struct, .Enum, .Union, .Opaque => refAllDeclsRecursive(@field(T, decl.name)),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
_ = @field(T, decl.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user