resharper-heapview icon indicating copy to clipboard operation
resharper-heapview copied to clipboard

Invalid "closure can be eliminated" hint with local methods

Open controlflow opened this issue 3 years ago • 1 comments

Static local functions are not introducing closures see for details: https://youtrack.jetbrains.com/issue/RSRP-487543

controlflow avatar Jan 17 '22 10:01 controlflow

Probable same issue here: https://youtrack.jetbrains.com/issue/RIDER-75451

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="LanguageExt.Core" Version="4.0.4" />
    </ItemGroup>
</Project>
public static class Program
{
    public static void Test()
    {
        var data = LanguageExt.Prelude.Atom<int>(default);
        var i = 42;
        data.Swap(_ => i); //   <- wrong Closure can be eliminated inspection
    }
}

StefanBertels avatar Mar 30 '22 14:03 StefanBertels

Swap is really overloaded to solve the issue of heap allocations: image The inspection is correct when applied to this Atom<T> API.

controlflow avatar Dec 31 '22 15:12 controlflow