Skip to content

False positive for RCS1074 depending on property ordering #1767

Description

@cbersch

The following example raises a wrong RCS1074 diagnostic in L7 (tested with Roslynator 4.15.0, .NET 10.0.300)

public readonly struct Foo
{
    public bool B { get; init; }

    public bool A { get; init; } = true;

    public Foo()
    {
    }
}
Image

Wrong, because removing the constructor leads to error CS8983: A 'struct' with field initializers must include an explicitly declared constructor.

After changing the order of properties A and B the diagnostic is not reported:

public readonly struct Foo
{
    public bool A { get; init; } = true;

    public bool B { get; init; }

    public Foo()
    {
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions