Skip to content

Fix S3253 FP: Don't raise for primary constructor in type declarations without parameters when they inherit from types with parameters #8436

@thomasfroehle

Description

@thomasfroehle

Description

S3253 is reported when a record with a parameterless constructor inherits another record that has parameters and passes them inline (instead of having an explicit base()-call).

Repro steps

public abstract record Base(string Value);

public record Foo() : Base("SomeValue");

Expected behavior

No S3253 is raised because the Foo()-constructor is not redundant.

Actual behavior

S3253 is raised.

Known workarounds

public abstract record Base(string Value);

public record Foo : Base
{
    public Foo() : base("SomeValue")
    {

    }
}

Related information

SonarAnalyzer.CSharp: 9.14.0.81108

Metadata

Metadata

Labels

False PositiveRule IS triggered when it shouldn't be.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions