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

Overload resolution prefers Span<T> over ReadOnlySpan<T> for collection expression #70318

Closed
cston opened this issue Oct 10, 2023 · 2 comments · Fixed by #70328
Closed

Overload resolution prefers Span<T> over ReadOnlySpan<T> for collection expression #70318

cston opened this issue Oct 10, 2023 · 2 comments · Fixed by #70328

Comments

@cston
Copy link
Member

cston commented Oct 10, 2023

Version Used:

Steps to Reproduce:

Compile and run:

using System;

class Program
{
    static void Main()
    {
        M([1, 2, 3]);
    }
    
    static void M(Span<int> span) { Console.WriteLine("Span<int>"); }
    static void M(ReadOnlySpan<int> span) { Console.WriteLine("ReadOnlySpan<int>"); }
}

See sharplab.io

Expected Behavior:
ReadOnlySpan<int>

Actual Behavior:
Span<int>

Reported by @stephentoub

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 10, 2023
@cston cston self-assigned this Oct 10, 2023
@cston cston added this to the 17.8 milestone Oct 10, 2023
@CyrusNajmabadi
Copy link
Member

Isn't span the more specific type, since it can be converted to ROS?

@jnm2
Copy link
Contributor

jnm2 commented Oct 10, 2023

We crossed the bridge of saying that some things are more important than "which is more specific" when we preferred ReadOnlySpan<T> over T[]. In ReadOnlySpan<T> vs T[], performance was more important.

In the case of ReadOnlySpan<T> over Span<T>, performance could again be more important than specificity; assembly data can be used with ReadOnlySpan and not Span.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants