Skip to content

IDE0251 doesn't factor in InlineArrays #71500

@stephentoub

Description

@stephentoub

Version Used:
Version 17.9.0 Preview 3.0 [34431.11.main]

Steps to Reproduce:

using System.Runtime.CompilerServices;

Console.WriteLine("Hello, world!");

internal struct Repro
{
    private Values _values;

    public void Populate()
    {
        Span<int> values = _values;
        for (int i = 0; i < values.Length; i++)
        {
            values[i] = i;
        }
    }
}

[InlineArray(4)]
internal struct Values
{
#pragma warning disable IDE0044 // Add readonly modifier
#pragma warning disable IDE0051 // Remove unused private members
    private int _field;
#pragma warning restore IDE0051
#pragma warning restore IDE0044
}

Expected Behavior:
No diagnostic on Populate.

Actual Behavior:
IDE0251 is raised on Populate to mark it as readonly. But you can't mark it as readonly; if you do, that then triggers an error on the casting of _values: "error CS9164: Cannot convert expression to 'Span' because it is not an assignable variable"

Metadata

Metadata

Labels

Area-IDEResolution-FixedThe bug has been fixed and/or the requested behavior has been implementeduntriagedIssues and PRs which have not yet been triaged by a lead

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions