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 S2094 FP: Records which set the base record's properties in their initializer #6953

Closed
sm-g opened this issue Mar 20, 2023 · 1 comment · Fixed by #6960
Closed

Fix S2094 FP: Records which set the base record's properties in their initializer #6953

sm-g opened this issue Mar 20, 2023 · 1 comment · Fixed by #6960
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Milestone

Comments

@sm-g
Copy link

sm-g commented Mar 20, 2023

Description

A C# record can specify a base record and set some of its properties in the call to the base constructor.

Repro steps

public abstract record RuleApplyResult(bool Success);

public record RuleApplyDone() : RuleApplyResult(true);                  // FP - RuleApplyDone is a more specific version of RuleApplyResult

public record RuleApplySkipped(string Reason) : RuleApplyResult(false); // FP - RuleApplySkipped is a more specific version of RuleApplyResult

Expected behavior

No issue should be raised for the descendant records.

Actual behavior

An issue is raised for the descendant (more specific) record.

Related information

v8.54

@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be. and removed Area: VB.NET VB.NET rules related issues. labels Mar 28, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title Fix S2094 FP: Allow to have empty class with non-empty ctor for base class Fix S2094 FP: Records which set the base record's properties in their initializer Mar 28, 2023
@zsolt-kolbay-sonarsource
Copy link
Contributor

Confirmed to be a valid FP.

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
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants