S1121 does not play well with the new record type in C# 9

The new “record” type in C# 9 is a very nice addition to the language if one, like myself, like use immutable types where appropriate. Unfortunately, Sonarlint gives of a lot of warnings when a copy of an existing instance is created and a field or two is changed using the “with” expression, like in the code below.

var person = new Person(“Joakim”, “Olsson”);
var brother = person with { FirstName = “David” };

Code like the one above is / will be used heavily by the C# community as more and more people begin to use C# 9 so I think Sonarlint should perhaps tweak the warning somehow?

Hello Joakim!
Welcome to the community and thank you for your feedback.
Also thank you for the clean code example. We will look at this problem and may be change something about this warnings.

Best regards.

hello @JoakimOlsson

We do not support yet records in our analyzer, we have MMF-2223 to implement support for records this year.

Thanks,
Andrei

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.