Skip to content

IDE0290 code fix is invalid in ref struct #73614

Closed

Description

Version Used: '4.11.0-1.24229.8 (28985c0)'. Language version: 12.0

Steps to Reproduce:

https://sharplab.io/#v2:EYLgtghglgdgPgAQEwEYCwAoTAnApgMwAIBnAF2wFcBjUwgZQjAAcAbXTAb00J8KeygA3CKVyEASrggATAPIwWATzpMIMADxUAFhGwA+QgH0y2ANyZuvBAGZ6jVrgAUkmfKUq1mnfpLkAlJY8XBi8oUYmhAC8vmaBhAC+FiFWtggALIQAsgD2grgAcrgAHqSOAclBcaHC2CSqMFHh5OYVCZiJGEA

ref struct Sample
{
    private ReadOnlySpan<char> _str;

    public Sample(ReadOnlySpan<char> str)
    {
        _str = str;
    }

    public void MoveNext()
    {
        var span = _str;
    }
}

Use the fix to convert to primary constructor and remove field

ref struct Sample(ReadOnlySpan<char> str)
{
    public void MoveNext()
    {
        // ❌ CS9110 Cannot use primary constructor parameter 'str' that has ref-like type inside an instance member
        var span = str;
    }
}

Diagnostic Id: IDE0290 Use primary Constructor

Expected Behavior: The code fix is not suggested

Actual Behavior: The code fix is suggested

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

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBughelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type

    Projects

    • Status

      Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions