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

[Proposal] Allow generic structs to match the unmanaged constraint #1923

Closed
SamPruden opened this issue Oct 9, 2018 · 2 comments
Closed

Comments

@SamPruden
Copy link

SamPruden commented Oct 9, 2018

void Foo<T>() where T : unmanaged => throw new NotImplementedException();

// This errors because it doesn't know that (int, int) is unmanaged.
Foo<(int, int)>();

I would like the above to work.

I am specifically focused on tuples in my use case, but more generally I would propose that unmanaged should be checked after resolving generics. Currently it seems that all generic structs are rejected by unmanaged. I propose that a generic struct should only be rejected when, after generic resolution, it has a field of a managed type.

struct IntWrapper { public int Value; }
struct GenericWrapper<T> { public T Value; }

IntWrapper can be used with the unmanaged constraint.

GenericWrapper<int> cannot. I propose that it should be able to be.

@ufcpp
Copy link

ufcpp commented Oct 9, 2018

Dup of #1504
This requires CLR change

@SamPruden
Copy link
Author

@ufcpp Oops, missed that. Thanks, I'll close this down then. It's a shame that it's blocked, but not very surprising.

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

2 participants