dotnet / roslynator

Roslynator is a set of code analysis tools for C#, powered by Roslyn.
https://josefpihrt.github.io/docs/roslynator
Other
3.09k stars 258 forks source link

RCS1214 Incorrect for Interpolation Handlers #1497

Closed EmmaJaneBonestell closed 3 months ago

EmmaJaneBonestell commented 3 months ago

Product and Version Used: Roslynator.Analyzera 4.12.4

Steps to Reproduce:

using System.Globalization;

public void foo()
{
    Span<char> bar = stackalloc char[6];
    bar.TryWrite(CultureInfo.InvariantInfo, $"foobar", out _);
}

Actual Behavior: $"foobar" is marked by RCS1214 as an unnecessary interpolation. Accepting the code fix and removing the interpolation causes an error:

bar.TryWrite(CultureInfo.InvariantInfo, "foobar", out _);

Expected Behavior: RCS1214 should not apply to interpolation handler parameters, e.g. this ref TryWriteInterpolatedStringHandler. Probably simpler just not to recommend it here, but it could also suggest a codefix to do something like "foobar".TryCopyTo(bar); instead.