dotnet/roslyn

Generic interface inheritance conflict with extension method

Open

#16.843 geöffnet am 31. Jan. 2017

Auf GitHub ansehen
 (11 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-CompilersBugConcept-Diagnostic Clarityhelp wanted

Repository-Metriken

Stars
 (20.414 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

I write 2 class inherit each other and each implement IEnumerable with difference generic type

Like this

public class A : IEnumerable<object>
{
    public IEnumerator<object> GetEnumerator()
    {
        throw new NotImplementedException();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        throw new NotImplementedException();
    }
}

public class B : A, IEnumerable<string>
{
    public new IEnumerator<string> GetEnumerator()
    {
        throw new NotImplementedException();
    }
}

////

	static void Test()
	{
		var a = new A();
		var b = new B();

		a.Select((item,i) => i);
		b.Select((item,i) => i);
	}

Instance from A work fine but B cannot use all generic function in System.Linq

image

It seem B was seen by compiler that it is just IEnumerable but not IEnumerable<string>. It still have Cast<> and OfType<> exposed

image

Contributor Guide