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

Generic extension method with in this parameter fails to compile #24641

Closed
controlflow opened this issue Feb 5, 2018 · 2 comments
Closed

Generic extension method with in this parameter fails to compile #24641

controlflow opened this issue Feb 5, 2018 · 2 comments

Comments

@controlflow
Copy link

Version Used:

master branch @ feb 5

Steps to Reproduce:

Compile the following code:

public static class C {
  public static ref readonly T E<T>(this ref T x) where T : struct => ref x;
}

Expected Behavior:

Successful compilation, the same as for ref extension version:

public static class C {
  public static ref readonly T E<T>(this ref T x) where T : struct => ref x;
}

Actual Behavior:

error CS8338: The first parameter of an 'in' extension method 'E' must be a value type

@sharwell
Copy link
Member

sharwell commented Feb 5, 2018

This seems very similar to #24601.

@controlflow
Copy link
Author

Thanks, @sharwell ! What a confusing corner case, I was not realized any kind of member access would copy the struct in generic code since compiler can't tell if T is readonly struct or not...

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