-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Disallow method parameter conversion of ref
to in
/ref readonly
#7820
Conversation
@@ -255,6 +274,25 @@ The same warning could be reported when using custom collection initializer or i | |||
|
|||
#### [Method conversions][method-conversions] | |||
|
|||
We could allow conversions of `ref` to `in`/`ref readonly`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a bit more clear? Like saying
We could allow conversions of
ref
parameters in lambda expressions toin / ref readonly
parameters
Similarly, for the purpose of anonymous function [[§10.7](https://github.com/dotnet/csharpstandard/blob/47912d4fdae2bb8c3750e6485bdc6509560ec6bf/standard/conversions.md#107-anonymous-function-conversions)] and method group [[§10.8](https://github.com/dotnet/csharpstandard/blob/47912d4fdae2bb8c3750e6485bdc6509560ec6bf/standard/conversions.md#108-method-group-conversions)] conversions, these modifiers are considered compatible | ||
(but any allowed conversion between different modifiers results in a warning): | ||
|
||
- `ref readonly` can be interchanged with `in` and converted to `ref` modifier (but `ref` cannot be converted to `ref readonly`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this wording confusing. We are not converting modifiers. Interchangeability is also a confusing term in this context, I think. Are we trying to say that a ref readonly
parameter of the target method is allowed to match in
or ref
parameter of the delegate, but ref
parameter of the target method is not allowed to match in
or ref readonly
parameter of the delegate? Consider using this wording then.
(but any allowed conversion between different modifiers results in a warning): | ||
|
||
- `ref readonly` can be interchanged with `in` and converted to `ref` modifier (but `ref` cannot be converted to `ref readonly`), | ||
- `in` can be converted to `ref` modifier, gated on LangVersion (but `ref` cannot be converted to `in`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider rewording as suggested for the previous bullet point. It actually feels like it would be better to have three bullet points.
- for
ref readonly
parameter of the target method - for
in
parameter of the target method - for
ref
parameter of the target method
@@ -255,6 +274,25 @@ The same warning could be reported when using custom collection initializer or i | |||
|
|||
#### [Method conversions][method-conversions] | |||
|
|||
We could allow conversions of `ref` method/lambda parameters to `in`/`ref readonly` delegate parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment for this statement. I have no idea what converting parameters mean, I do not think language has a concept like that.
Done with review pass (commit 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 3)
Related to dotnet/roslyn#71383.
Corresponding roslyn implementation: dotnet/roslyn#71531
Test plan: dotnet/roslyn#68056