Commit 9c66fdadc7

alichraghi <alichraghi@pm.me>
2022-07-13 16:16:10
std.testing: add `refAllDeclsRecursive` function
1 parent 43770c0
Changed files (1)
lib
lib/std/testing.zig
@@ -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);
+        }
+    }
+}