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 S1694 FP: Abstract class with field or constructor #9494

Closed
paulhickman-ec opened this issue Jul 1, 2024 · 0 comments · Fixed by #9504
Closed

Fix S1694 FP: Abstract class with field or constructor #9494

paulhickman-ec opened this issue Jul 1, 2024 · 0 comments · Fixed by #9504
Assignees
Labels
Area: C# C# rules related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@paulhickman-ec
Copy link

Description

The code below triggers S1694. However, in the case where there is logic using the constructor arguments in the abstract class, it should not be converted to an interface.

Repro steps

public abstract class Foo
{
    protected int _data;

    protected Foo(int data)
    {
        _data = data * 2;
    }

    public abstract void Bar();
}

Expected behavior

S1694 should not fire as the constructor argument/code makes it unsuitable to convert to an interface. This code could be quite complex and should be shared between all subclasses.

Actual behavior

S1694 does trigger.

Known workarounds

Suppress the issue.

Related information

  • .Net 8
  • SonarAnalyzer.CSharp 9.28.094264
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title Fix S1694: Abstract class with constructor arguments/body should not be converted to an interface Fix S1694 FP: Abstract class with field or constructor Jul 2, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Jul 2, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added this to the 9.29 milestone Jul 2, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added the Sprint: Hardening Fix FPs/FNs/improvements label Jul 2, 2024
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. Sprint: Hardening Fix FPs/FNs/improvements 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