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

Add fixer when for params span overloads are used with Expression selected #74030

Closed
KathleenDollard opened this issue Jun 17, 2024 · 0 comments · Fixed by #76124
Closed

Add fixer when for params span overloads are used with Expression selected #74030

KathleenDollard opened this issue Jun 17, 2024 · 0 comments · Fixed by #76124
Assignees
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@KathleenDollard
Copy link

Summary

Span and ReadOnlySpan overloads are preferred for params arguments, as described in the following code:

using System.Linq.Expressions;
internal class Program
{
    private static void Main(string[] args)
    {
        Expression<Func<string>> f = ()=> Test('a', 'b'); // before
        // error CS8640: Expression tree cannot contain value of ref struct or restricted type 'ReadOnlySpan'.
        // error CS9226: An expression tree may not contain an expanded form of non-array params collection parameter.
        Expression<Func<string>> f2 = ()=> Test(new[] { 'a', 'b' });
    }

    static string Test(params char[] characters) => "";
    static string Test(params ReadOnlySpan<char> characters) => "";
}

Background and Motivation

C# prefers the Span and ReadOnlySpan overloads to improve performance, which is desirable in almost all cases. However, there is no resourcing to update expression trees to handle ref struct issues like this one. As a result, users that have expression trees will receive the errors described above.

Proposed Feature

Add a fixer when this error occurs so the user is gently led to the explicit array overloads.

Alternative Designs

The C# LDM has considered whether to special case expression trees and decided not to do this at this time.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jun 17, 2024
@deepakrathore33 deepakrathore33 added the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label Oct 23, 2024
@deepakrathore33 deepakrathore33 added this to the Backlog milestone Oct 23, 2024
@deepakrathore33 deepakrathore33 removed the untriaged Issues and PRs which have not yet been triaged by a lead label Oct 23, 2024
@CyrusNajmabadi CyrusNajmabadi self-assigned this Nov 26, 2024
@CyrusNajmabadi CyrusNajmabadi modified the milestones: Backlog, 17.13 Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
None yet
3 participants