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

Offer "Use collection expressions" when the chosen overload would switch #74931

Closed
jnm2 opened this issue Aug 28, 2024 · 0 comments · Fixed by #74934
Closed

Offer "Use collection expressions" when the chosen overload would switch #74931

jnm2 opened this issue Aug 28, 2024 · 0 comments · Fixed by #74934
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@jnm2
Copy link
Contributor

jnm2 commented Aug 28, 2024

Version Used: 17.12.0 preview 1.0

"Use collection expression" appears to only be offered if it would not cause the chosen overload to switch. However, this would often be useful. It's likely a poor API design that has significant semantics changes between overloads just based on the type of the collection.

string.Split added a params ReadOnlySpan<char> in .NET 9, and the "use collection expression" fix stopped being offered on string.Split because of this. However, it's vastly preferable to switch to calling the ReadOnlySpan overload.

To play it uber-safe, this code suggestion could have the "may changes semantics" notation added to it.

class C
{
    void M(char c)
    {
        Split(new[] { c });
    }

    void Split(char[] p) { }
    void Split(ReadOnlySpan<char> p) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
1 participant