Skip to content

RCS1214 Incorrect for Interpolation Handlers #1497

@StDymphna

Description

@StDymphna

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions