-
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
Collection expressions: require Add method callable with a single argument for class and struct types that do not use [CollectionBuilder] #8022
Conversation
…ument for class and struct types that do not use [CollectionBuilder]
proposals/params-collections.md
Outdated
in which case the *element type* is the *iteration type* | ||
- The *type* has a constructor that can be invoked with no arguments, and the constructor is at least as accessible as the declaring member. | ||
- The *type* has an instance (not an extension) method `Add` where: | ||
- The method can be invoked with a single argument and the corresponding parameter is either by value or `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.
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.
Probably the bullet point should say the following instead:
- The method can be invoked with a single value (vs. ref/out/in) argument.
proposals/params-collections.md
Outdated
- The method can be invoked with a single argument and the corresponding parameter is either by value or `in`. | ||
- If the method is generic, the type arguments can be inferred from the argument. | ||
- The method is at least as accessible as the declaring member. | ||
- In which case the *element type* is the [*iteration type*](https://github.com/dotnet/csharpstandard/blob/draft-v9/standard/statements.md#1395-the-foreach-statement) of the *type*. |
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.
- In which case the element type is the iteration type of the type.
This probably shouldn't be a bullet point. This is not one of the conditions #Closed
in which case the *element type* is the *iteration type* of the *type*. | ||
* The *type* has an *[applicable](https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/expressions.md#11642-applicable-function-member)* constructor that can be invoked with no arguments, and the constructor is accessible at the location of the collection expression. | ||
* If the collection expression has any elements, the *type* has an instance or extension method `Add` where: | ||
* The method can be invoked with a single argument and the corresponding parameter is either by value or `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.
* The method can be invoked with a single argument and the corresponding parameter is either by value or `in`. | ||
* If the method is generic, the type arguments can be inferred from the collection and argument. | ||
* The method is accessible at the location of the collection expression. | ||
* In which case the *element type* is the [*iteration type*](https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/statements.md#1295-the-foreach-statement) of the *type*. |
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.
- In which case the element type is the iteration type of the type.
Similar comment as for params spec #Closed
Done with review pass (commit 1) |
The main observable change - the original (unconverted) params arguments are used in the process of populating target collection. Spec changes: dotnet/csharplang#8022 Fixes #72098
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)
Previously, collection expression conversion required an
Add
method callable with a single argument of the iteration type if the collection expression has any elements. This is relaxed to anAdd
method callable with a single argument, without a requirement on the argument type.