sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

S2930 doesn't recognize IAsyncDisposable

Open wiciok opened this issue 2 years ago • 1 comments

Description

S2930 doesn't recognize Dispose() and DisposeAsync() calls made in DisposeAsync() method, resulting in false-positives: image

Issue is similar to #3324

Repro steps

Analyze following code:

namespace IAsyncDisposableBug
{
    public sealed class Test : IAsyncDisposable
    {
        private readonly FileStream stream;

        public Test()
        {
            stream = new FileStream("C://some-path", FileMode.CreateNew);
        }

        public async ValueTask DisposeAsync()
        {
            await stream.DisposeAsync();
        }
    }
}

Expected behavior

S2930 should not be raised if Dispose/DisposeAsync is called in DisposeAsync() method from IAsyncDisposable

Actual behavior

S2930 is raised when Dispose/DisposeAsync is called in DisposeAsync() method from IAsyncDisposable

Known workarounds

None

Related information

  • Visual Studio version: 17.2.6
  • SonarLint for Visual Studio: 6.6.0.49766
  • Operating System: Windows 10

wiciok avatar Jul 20 '22 09:07 wiciok

Hello @wiciok, Thank you for the report. I confirm this is a false positive.

Dear @wiciok ! The fix for this issue will be available in the next release. Thank you for reporting it and helping us improve the analyzer.