Commit b45c6c757c

Andrew Kelley <andrew@ziglang.org>
2022-04-01 04:05:24
std.hash_map: workaround for circular dependency
See #11367 It's debatable whether this ends up being a legitimate compile error or whether the lang spec allows this test case. For now this workaround seems very reasonable; delaying comptime execution of `verifyContext` until the struct is instantiated.
1 parent 26253ac
Changed files (1)
lib
lib/std/hash_map.zig
@@ -370,12 +370,15 @@ pub fn HashMap(
     comptime Context: type,
     comptime max_load_percentage: u64,
 ) type {
-    comptime verifyContext(Context, K, K, u64, false);
     return struct {
         unmanaged: Unmanaged,
         allocator: Allocator,
         ctx: Context,
 
+        comptime {
+            verifyContext(Context, K, K, u64, false);
+        }
+
         /// The type of the unmanaged hash map underlying this wrapper
         pub const Unmanaged = HashMapUnmanaged(K, V, Context, max_load_percentage);
         /// An entry, containing pointers to a key and value stored in the map
@@ -694,11 +697,13 @@ pub fn HashMapUnmanaged(
 ) type {
     if (max_load_percentage <= 0 or max_load_percentage >= 100)
         @compileError("max_load_percentage must be between 0 and 100.");
-    comptime verifyContext(Context, K, K, u64, false);
-
     return struct {
         const Self = @This();
 
+        comptime {
+            verifyContext(Context, K, K, u64, false);
+        }
+
         // This is actually a midway pointer to the single buffer containing
         // a `Header` field, the `Metadata`s and `Entry`s.
         // At `-@sizeOf(Header)` is the Header field.