controlflow / resharper-heapview

ReSharper Heap Allocations Viewer plugin
MIT License
303 stars 28 forks source link

Invalid "closure can be eliminated" hint with local methods #93

Closed controlflow closed 1 year ago

controlflow commented 2 years ago

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

StefanBertels commented 2 years ago

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
    }
}
controlflow commented 1 year ago

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