RefactoringEssentials icon indicating copy to clipboard operation
RefactoringEssentials copied to clipboard

RECS0015 leads to infinite recursion

Open n9 opened this issue 7 years ago • 1 comments
trafficstars

Let's have the following code:

public static class SimpleTextEx
{
    public static SimpleText Times(this int number, SimpleText text)
    {
        return TextEx.Times(number, text); // <-- RECS0015 // If an extension method is called as static method convert it to method syntax
    }
}

public static class TextEx
{
    public static string Times(this int number, string text)
    {
        throw new NotImplementedException();
    }
}

public class SimpleText
{
    public static implicit operator string(SimpleText text)
    {
        throw new NotImplementedException();
    }

    public static implicit operator SimpleText(string text)
    {
        throw new NotImplementedException();
    }
}

RE incorrectly suggests to replace the static call with extension call. This however produces the infinite recursion.

n9 avatar Jun 14 '18 11:06 n9

Similar situation is following:

    public class Foo { }

    public static class FooEx
    {
        public static string GetType(this Foo foo)
        {
            throw new NotImplementedException();
        }
    }

    class Program
    {
        static string Bar(Foo foo)
        {
            return FooEx.GetType(foo); // <-- RECS0015 // If an extension method is called as static method convert it to method syntax
        }
    }

(Fortunately, this however causes a compilation error.)

n9 avatar Jun 14 '18 11:06 n9