Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible null reference argument in call to IEqualityComparer #744

Open
DorianGreen opened this issue Jan 28, 2025 · 2 comments
Open

Possible null reference argument in call to IEqualityComparer #744

DorianGreen opened this issue Jan 28, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@DorianGreen
Copy link

Describe the bug

I am getting the following analyzer warning:

Possible null reference argument for parameter 'y' in 'bool IEqualityComparer.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

@DorianGreen DorianGreen added the bug Something isn't working label Jan 28, 2025
@SteveDunn
Copy link
Owner

Thank you for the feedback. I'll take a look at this issue soon.

@SteveDunn
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants