diff --git a/AK/HashMap.h b/AK/HashMap.h index d4d56968e2e..979740ac495 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -228,8 +228,13 @@ public: auto it = find(key); if (it != end()) return it->value; - auto result = TRY(try_set(key, initialization_callback())); - VERIFY(result == HashSetResult::InsertedNewEntry); + if constexpr (FallibleFunction) { + auto result = TRY(try_set(key, TRY(initialization_callback()))); + VERIFY(result == HashSetResult::InsertedNewEntry); + } else { + auto result = TRY(try_set(key, initialization_callback())); + VERIFY(result == HashSetResult::InsertedNewEntry); + } return find(key)->value; }