From b45c6c757cb4a16f5021c8bf057d14183036f14c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 31 Mar 2022 19:05:24 -0700 Subject: [PATCH] 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. --- lib/std/hash_map.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 8c4e6b2581..96df243f6e 100644 --- a/lib/std/hash_map.zig +++ b/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.