roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

Refactoring "invert if (recursively)" causes compiler error

Open josefpihrt opened this issue 2 years ago • 1 comments
trafficstars

Product and Version Used: 4.3.0

Before:

class C
{
    void M(bool p, bool q, bool r)
    {
        if (r) // Invoke "Invert if (recursively)" here
        {
            if (p)
            {
                var x = 1;
                M2();
            }

            if (q)
            {
                var x = 2;
                M2();
            }
        }
    }

    void M2()
    {
    }
}

After:

class C
{
    void M(bool p, bool q, bool r)
    {
        if (!r)
        {
            return;
        }

        if (p)
        {
            var x = 1; // compiler error here
            M2();
        }

        if (!q)
        {
            return;
        }

        var x = 2;
        M2();
    }

    void M2()
    {
    }
}

josefpihrt avatar Jul 25 '23 13:07 josefpihrt