Open
Description
Analyzer
Diagnostic ID: CA1861: Avoid constant arrays as arguments
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 8.0.100
Describe the bug
CA1861 does not work with C#12 array syntax.
Steps To Reproduce
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>
</Project>
namespace ClassLibrary1
{
public class Class1
{
public void Do()
{
DoSomething(new int[] { 1, 2 }); // CA1861
DoSomething([1, 2]); // no CA1861
}
public static void DoSomething(int[] ints)
{
}
}
}
Expected behavior
CA1861 on both lines