BADF00D / DisposableFixer

This is a Visual Studio Extension and NuGet package that should identify and fix problems as memleaks while using IDisposables.
Other
35 stars 7 forks source link

Unexpected DF0001 when yield returning a disposable #117

Closed AartBluestoke closed 5 years ago

AartBluestoke commented 5 years ago

Prerequisites

Description

yield return of a disposable warns about an undisposed object, while a simple return is flagged safe. ; i would not expect this inconsistency.

Source Code

    class someTest
    {
        static IDisposable f()=>null;
        IEnumerable<IDisposable> f2()
        {
            foreach(var r in Enumerable.Range(1, 10))
            {
                yield return f(); // warning here -- would expect the warning status to be the same as below.
            }
        }

        IDisposable f3()
        { 
            return f(); // no warning here
        }
    }

Screenshot

image

BADF00D commented 5 years ago

Hi, thanks for reporting. Actually I never thought about this "feature" of yielding an IDisposable. Should be no big deal

BADF00D commented 5 years ago

Will be part of release 1.7.0