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

Disallow method parameter conversion of ref to in/ref readonly #7820

Merged
merged 3 commits into from
Jan 15, 2024

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Jan 5, 2024

Related to dotnet/roslyn#71383.
Corresponding roslyn implementation: dotnet/roslyn#71531
Test plan: dotnet/roslyn#68056

@jjonescz jjonescz marked this pull request as ready for review January 5, 2024 16:14
@jjonescz jjonescz requested a review from a team as a code owner January 5, 2024 16:14
@@ -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`.
Copy link
Member

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 to in / 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`),
Copy link
Contributor

@AlekseyTs AlekseyTs Jan 11, 2024

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`).
Copy link
Contributor

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.
Copy link
Contributor

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.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 2)

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 3)

@jjonescz jjonescz merged commit d8d69d2 into dotnet:main Jan 15, 2024
1 check passed
@jjonescz jjonescz deleted the RefInConversion branch January 15, 2024 12:54
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

Successfully merging this pull request may close these issues.

3 participants