C# compiler generates an error when overloading generics. - by LinoB

Status : 


Sign in
to vote
ID 800922 Comments
Status Active Workarounds
Type Bug Repros 0
Opened 9/16/2013 3:52:23 AM
Access Restriction Public


if you have the two generic function with different constraints on generic types (where keyword) the compiler generates an error when it shouldn't:
error CS0111: Type 'LinoBarreca.Test' already defines a member called 'Choose' with the same parameter types.

The compiler must be able to pick the appropriate version based on the parameter type without giving an error...
It could make sense if the two "generics" are derived one from the other but not if they are totally different.
Sign in to post a comment.
Posted by Mads [MSFT] on 1/15/2014 at 9:43 AM
Thanks for your suggestion!

This is essentially a proposal that overload resolution should take constraints into account, weeding out candidates where the type arguments inferred or passed do not fulfill their corresponding constraints. Also we would have to establish conditions under which the methods would both be allowed to coexist, even though their signatures are the "same".

We chose not to do this originally because we wanted the rules around generic methods to be as simple as possible (they are already plenty complicated!). That said, I am certainly sympathetic to your scenario - I have found myself in the same situation multiple times, and heard about it from others.

We'll try to take another look at whether we can come up with some good rules that would allow this, but to be honest I think the chances are slim that a) we can, and b) we would prioritize to do this over the other additions we are targeting for the language this time around. For that reason I'll resolve as "By Design". If we don't get to it this time, the feature remains on our list of "features we may do one day", a list that we revisit at the beginning of every cycle.

Thanks again!

Mads Torgersen, C# Language PM
Posted by LinoB on 9/20/2013 at 3:30 AM
Just look at the "steps to reproduce" section here.
There's the code that causes the error.

(and this site sucks. I had to post the same comment at least 10 times in 3 different days because it always fails storing it).
Posted by Microsoft on 9/19/2013 at 11:26 PM
Hello again. We wanted to give you a quick reminder that to efficiently investigate and reproduce your issue, we need you submit the additional information we requested.
Posted by Microsoft on 9/17/2013 at 5:54 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.

Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

We look forward to hearing from you with this information.
Posted by Microsoft on 9/16/2013 at 4:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)