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:
parent
06a40184ee
commit
fbbe94bfa8
3 changed files with 75 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue