Closed as not planned
Description
Version Used:
$ dotnet --version
9.0.102
Steps to Reproduce:
Run dotnet build
on a simple project with .csproj
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<WarningsAsErrors>IDE0005</WarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>CS1591;CS8321</NoWarn>
</PropertyGroup>
</Project>
and Program.cs
:
using System.Data;
using System.Linq;
static void Test(EnumerableRowCollection<object> target)
{
// These two lines call the same extension method, Linq is not used.
// But uncommenting the first line makes IDE0005 go away incorrectly
// _ = target.Where(_ => true);
_ = EnumerableRowCollectionExtensions.Where(target, _ => true);
}
Diagnostic Id:
IDE0005: Using directive is unnecessary.
Expected Behavior:
IDE0005
is triggered when nothing from System.Linq
is used.
Actual Behavior:
using System.Linq;
does not cause IDE0005
build error.
This is because the Roslyn logic in WithUsingNamespacesAndTypesBinder.cs
that determines which extension methods from usings are being used does not distinguish between overloads. It only looks at the method name and arity, not the (this
) parameter type.
Activity