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

Collection expressions: prefer ReadOnlySpan<T> over Span<T> in overload resolution #7591

Merged
merged 2 commits into from
Oct 12, 2023

Conversation

cston
Copy link
Member

@cston cston commented Oct 10, 2023

@cston cston merged commit 82304fc into dotnet:main Oct 12, 2023
1 check passed
@cston cston deleted the 70318 branch October 12, 2023 18:54
> * **`E` is a *collection expression* and one of the following holds:**
> * **`T₁` is `System.ReadOnlySpan<E₁>`, and `T₂` is `System.Span<E₂>`, and an implicit conversion exists from `E₁` to `E₂`**
> * **`T₁` is `System.ReadOnlySpan<E₁>` or `System.Span<E₁>`, and `T₂` is an *array_or_array_interface_or_string_type* with *iteration type* `E₂`, and an implicit conversion exists from `E₁` to `E₂`**
> * **`T₁` is not a *span_type*, and `T₂` is not a *span_type*, and an implicit conversion exists from `T₁` to `T₂`**
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I wasn't sure why the qualifier "not a span_type" was needed here. Maybe without it, we would consider array to be "more derived" than span and therefore better?

Have we fully tested the difference in the betterness rules for a user-defined span type versus System.Span? e.g. if a user-defined ref struct collection were implicitly convertible from array, then array would be a better conversion from collection-expression, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, "not a span_type" is needed to avoid allowing an implicit conversion from span to array.

Added tests to dotnet/roslyn#70328 for a ref struct collection that is implicitly convertible to array. Thanks.

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.

4 participants