Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer generic types of type constraint. #11242

Closed
UnoSD opened this issue May 11, 2016 · 3 comments
Closed

Infer generic types of type constraint. #11242

UnoSD opened this issue May 11, 2016 · 3 comments

Comments

@UnoSD
Copy link

UnoSD commented May 11, 2016

I apologies in advance as I am almost sure this will be a duplicate, but I cannot find it.

Has this been considered? When I have a generic type with, as type constraint, another generic type, I don't want to specify the constraints of the constraint in the main generic as they could easily be inferred:

Nice to have:
class Generic where T : OtherGeneric { }

Instead of:
class Generic<T, TOther> where T : OtherGeneric { }

@HaloFour
Copy link

I want to say that I've seen a dupe of this as well but I can't find it at the moment.

In my opinion I would prefer that the class signature contain the two generic type arguments because even if the C# compiler could infer that second type parameter the resultant CLR generic type will have an arity of two, Generic2[T, TOther]. I also like the check that the C# compiler would provide in ensuring that any generic type parameters used in the constraint are in scope, so that Generic<T1, TOther> where T : OtherGenericdoesn't accidentally becomeGeneric<T1, TOther, TOtter> where T : OtherGeneric`.

@UnoSD
Copy link
Author

UnoSD commented May 11, 2016

It could also infer it just in the usages and not in the declaration, that would be a good step forward already. (The inference could be implicit and the underlying type could stay as Generic`2[T, TOther].

@khellang
Copy link
Member

khellang commented May 11, 2016

Dupe of #5023, maybe also #7763. PR at #7850; closed (for now) because of breaking changes.

@UnoSD UnoSD closed this as completed May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants