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

Add test for ByRefLike testing #99415

Merged

Conversation

AaronRobinsonMSFT
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented Mar 7, 2024

When constraints are across multiple generic parameters, they do not flow.

class C<T, U>
    where T: allows ref struct
    where U: T
{ }

interface I1 {}
ref struct S1 : I1 {}

new C<I1, S1>(); // Invalid.
new C<S1, S1>(); // Invalid.
new C<int, int>(); // Valid.

From the IL perspective, the fix would be to apply the ref struct constraint on both parameters.

class C<T, U>
    where T: allows ref struct
    where U: T, allows ref struct // Or whatever gesture is expected.
{ }

are across multiple generic parameters.
@AaronRobinsonMSFT
Copy link
Member Author

@lambdageek
Copy link
Member

From the IL perspective, the fix would be to apply the ref struct constraint on both parameters.

I agree. I would expect that new C<I1, S1> is invalid because S1 is a ref struct and U does not allow ref structs - it doesn't matter whether T allows them or not.

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 709097d into dotnet:main Mar 7, 2024
101 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the constraint_test_byreflike branch March 7, 2024 21:13
@github-actions github-actions bot locked and limited conversation to collaborators Apr 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants