False positive for CA2263 with codefix changing code functionality.
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
.NET SDK 10.0.102
NuGet Microsoft.CodeAnalysis.NetAnalyzers version 10.0.100
### Describe the bug
CA2263 is raised and the code fix creates code that compiles but is functionally different.
### To Reproduce
```csharp
internal sealed class SkipTypes()
{
private static System.Collections.Immutable.ImmutableHashSet s_SkippedTypes = System.Collections.Immutable.ImmutableHashSet.Create(typeof(Type));
public static void AddIgnoreType(Type typeToIgnore)
{
if (!s_SkippedTypes.Contains(typeToIgnore))
{
s_SkippedTypes = s_SkippedTypes.Add(typeToIgnore);
}
}
}
```
Raises:
The code fix will change the field initialization into:
```csharp
private static System.Collections.Immutable.ImmutableHashSet s_SkippedTypes = System.Collections.Immutable.ImmutableHashSet.Create();
```
Unlike the original code which created a hashset with 1 element, this creates an empty hashset.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.