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

Fix S4035: FP for abstract declarations #2322

Closed
Corniel opened this issue Mar 6, 2019 · 1 comment · Fixed by #2565
Closed

Fix S4035: FP for abstract declarations #2322

Corniel opened this issue Mar 6, 2019 · 1 comment · Fixed by #2565
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@Corniel
Copy link
Contributor

Corniel commented Mar 6, 2019

Description

public abstract class ValueObject<T> : IEquatable<T> where T : ValueObject<T>
{
    public abstract bool Equals(T other); // compliant
}

public class MyValueObject : ValueObject<MyValueObject>
{
    public override bool Equals(MyValueObject other)
    {
        return RefrenceEquals(this, other); //non-compliant
    }
}

public sealed class MySealedValueObject : ValueObject<MySealedValueObject >
{
    public override bool Equals(MySealedValueObject  other)
    {
        return RefrenceEquals(this, other); //compliant
    }
}

To me, this should not raise the this concern on the abstract class with an abstract method. The implementing class should, if not sealed.

Related information

@andrei-epure-sonarsource andrei-epure-sonarsource added this to the Support milestone Apr 17, 2019
@christophe-zurn-sonarsource christophe-zurn-sonarsource added Area: C# C# rules related issues. Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. labels Jul 15, 2019
@christophe-zurn-sonarsource
Copy link
Contributor

Hello @Corniel,
Indeed, for the same reason Rule S4035 does not raise an issue for virtual Equals method, it should also not raise issue for abstract Equals method.

    public abstract class ValueObject<T> : IEquatable<T> where T : ValueObject<T>  // FP
    {
        public abstract bool Equals(T other);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants