Skip to content

Commit

Permalink
Merge pull request #1579 from AArnott/dev/andarno/compilerWarningFix
Browse files Browse the repository at this point in the history
Fix compiler warning that appears with VS 2022 Update 6 preview
  • Loading branch information
AArnott committed Mar 16, 2023
2 parents c3b4a71 + 158c6ab commit cb0ad5d
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public bool TryAdd(Type key, TValue value)

public bool TryAdd(Type key, Func<Type, TValue> valueFactory)
{
return this.TryAddInternal(key, valueFactory, out TValue _);
return this.TryAddInternal(key, valueFactory, out TValue? _);
}

private bool TryAddInternal(Type key, Func<Type, TValue> valueFactory, [MaybeNullWhen(false)] out TValue resultingValue)
private bool TryAddInternal(Type key, Func<Type, TValue> valueFactory, out TValue resultingValue)
{
lock (this.writerLock)
{
Expand Down Expand Up @@ -91,7 +91,7 @@ private bool TryAddInternal(Type key, Func<Type, TValue> valueFactory, [MaybeNul
}
}

private bool AddToBuckets(Entry[] buckets, Type newKey, Entry? newEntryOrNull, Func<Type, TValue>? valueFactory, out TValue? resultingValue)
private bool AddToBuckets(Entry[] buckets, Type newKey, Entry? newEntryOrNull, Func<Type, TValue>? valueFactory, out TValue resultingValue)
{
var h = (newEntryOrNull != null) ? newEntryOrNull.Hash : newKey.GetHashCode();
if (buckets[h & (buckets.Length - 1)] == null)
Expand Down Expand Up @@ -180,11 +180,7 @@ public TValue GetOrAdd(Type key, Func<Type, TValue> valueFactory)
return v;
}

if (!this.TryAddInternal(key, valueFactory, out v) && !this.TryGetValue(key, out v))
{
throw new InvalidOperationException("Failed to get or add.");
}

this.TryAddInternal(key, valueFactory, out v);
return v;
}

Expand Down

0 comments on commit cb0ad5d

Please sign in to comment.