fix(result): Result<T> hash collision

A success result wrapping a value whose GetHashCode is 0 (e.g. Result<int>
with 0) collides with a failure result, both hashing to 0.
This commit is contained in:
Louis Seubert 2026-07-12 18:32:16 +02:00
commit fbbe94bfa8
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
3 changed files with 75 additions and 3 deletions

View file

@ -181,7 +181,12 @@ public partial class Result<T> : IEquatable<Result<T>>, IEquatable<T>
return comparer.GetHashCode(result.Value);
}
return 0;
if (result is { IsSuccess: true, Value: null })
{
return 0;
}
return result.Error?.GetHashCode() ?? 0;
}
}