Possible null reference argument in call to IEqualityComparer
Describe the bug
I am getting the following analyzer warning:
Possible null reference argument for parameter 'y' in 'bool IEqualityComparer<EntityName>.Equals(EntityName x, EntityName y)'.
The generated code looks like this:
public global::System.Boolean Equals(EntityName? other, global::System.Collections.Generic.IEqualityComparer<EntityName> comparer)
{
return comparer.Equals(this, other);
}
Steps to reproduce
using Vogen v6.0.0
create a value object:
[ValueObject<string>]
public sealed partial class EntityName
{
private static Validation Validate(string input) => !string.IsNullOrWhiteSpace(input) && input.Length <= 50
? Validation.Ok
: Validation.Invalid("Customer IDs must be greater than 0.");
}
run build with analyzers
Expected behaviour
I would expect a pre-null check before calling the comparer
Thank you for the feedback. I'll take a look at this issue soon.
Hi @DorianGreen - have you got a small repo project as I'm unable to reproduce this. The generated code looks correct : IEqualityComparer has a method signature of bool Equals(T? x, T? y); in my test project.
Maybe it's a mismatch of nullability scopes? What's your project configured for? And what's the nullability of the scope where you value object is declared?
Hi @DorianGreen - just looking through issues now that I've got a bit of spare time. Have you got a small repro project that I can use?
This was fixed and is now in 8.0.1 - thanks for the report!