roslynator
roslynator copied to clipboard
RCS0023 incorrectly tries to enforce formatting of non-existent braces on record structs
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 :smile: .
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)
{
}
Hi,
Sorry, but I'm not able to reproduce this bug.
I forgot to mention that it appears to only happen on dotnet build
in a project. If I remove my workaround and use the short syntax again, I don't immediately see any errors, but if I try to build, there is always a compiler error:
CSC : error RCS0023: Format type declaration's braces. [/home/.../Foo.csproj]
Same here, and as @NoTuxNoBux shown, the message does not point to the file in which the supposed problem happens, showing only the project, making it hard to know that it was actually caused by some readonly record struct
. I olny found that out because of this issue right here