authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2022-07-13 18:46:10+04:30
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-16 12:33:25+03:00
log9c66fdadc709ca4c00b08aa8fa4dc6312cb559c3
tree26abeca76f7b54eb02a0efd65c043b4aa25b49f3
parent43770c010321d965aba716d717e8470ae0ae966d

std.testing: add `refAllDeclsRecursive` function


1 files changed, 16 insertions(+), 0 deletions(-)

lib/std/testing.zig+16
...@@ -723,3 +723,19 @@ pub fn refAllDecls(comptime T: type) void {...@@ -723,3 +723,19 @@ pub fn refAllDecls(comptime T: type) void {
723 if (decl.is_pub) _ = @field(T, decl.name);723 if (decl.is_pub) _ = @field(T, decl.name);
724 }724 }
725}725}
726
727/// Given a type, and Recursively reference all the declarations inside, so that the semantic analyzer sees them.
728/// For deep types, you may use `@setEvalBranchQuota`
729pub fn refAllDeclsRecursive(comptime T: type) void {
730 inline for (comptime std.meta.declarations(T)) |decl| {
731 if (decl.is_pub) {
732 if (@TypeOf(@field(T, decl.name)) == type) {
733 switch (@typeInfo(@field(T, decl.name))) {
734 .Struct, .Enum, .Union, .Opaque => refAllDeclsRecursive(@field(T, decl.name)),
735 else => {},
736 }
737 }
738 _ = @field(T, decl.name);
739 }
740 }
741}