Skip to content

RCS0023 incorrectly tries to enforce formatting of non-existent braces on record structs #920

@NoTuxNoBux

Description

@NoTuxNoBux

Product and Version Used: Roslynator 4.1.1.

Steps to Reproduce:

Create a readonly record struct:

public readonly record struct Foo(string Bar);

Roslynator will complain about braces that are not relevant to records:

CSC : error RCS0023: Format type declaration's braces. [Foo.csproj]

Expected Behavior:

Roslynator does not complain about braces on readonly record structs as they don't have any in this case.

Context

It is noteworthy to mention that the following types of records definitions work without issue:

public record Foo(string Bar);
public record class Foo(string Bar);

It seems to be related specifically to record struct.

Ironically if you do try to add braces, RCS1251 starts complaining that they are redundant 😄 .

Workaround (as I can't seem to surpress this error directly, either):

using System.Diagnostics.CodeAnalysis;

[SuppressMessage("Roslynator.CodeAnalysis.Analyzers", "RCS1251", Justification = "Using useless parantheses is a workaround for https://github.com/JosefPihrt/Roslynator/issues/920, which cannot be surpressed")]
public readonly record struct Foo(string Bar)
{
}

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions