dotnet / dotnet/sdk

[11.0-preview.2] CA1517 false positive

Closed
#53,388 2 comments 2 reactions 2 assignees Claimed by @jeffhandley View on GitHub
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug

A method that writes to a `Span` generates a false-positive warning of `warning CA1517: Parameter 'values' can be declared as 'ReadOnlySpan' instead of as 'Span'`.

### To Reproduce

Run the following program:

```csharp
#:property AnalysisMode=All

Span values = ['A', 'B', 'C', 'D'];
Console.WriteLine(values); // Output: ABCD

Swapper.Swap(values, 1, 2);
Console.WriteLine(values); // Output: ACBD

internal static class Swapper
{
public static void Swap(Span values, int x, int y)
{
(values[x], values[y]) = (values[y], values[x]);
}
}
```

### Exceptions (if any)

None.

### Further technical details

.NET SDK `11.0.100-preview.2.26159.112`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.