Skip to content

IDE0044 "make field readonly" false positive #57983

@Sergio0694

Description

@Sergio0694

Version Used: VS 17.0.1

Steps to Reproduce:

  1. Paste the following code:
using System.Runtime.CompilerServices;

public class Test
{
    private ulong nextD3D12ComputeFenceValue;

    internal void Repro()
    {
        ref ulong d3D12FenceValue = ref Unsafe.NullRef<ulong>();

        d3D12FenceValue = ref nextD3D12ComputeFenceValue;

        d3D12FenceValue++;
    }
}
  1. Observe the "make field readonly" code fix on the nextD3D12ComputeFenceValue field. Applying that will result in a compiler error, as we're getting a ref to that field within Repro(), which will not build if the field was readonly.

Expected Behavior:

No diagnostics, this code is fine.

Actual Behavior:

IDE0044 is produced on that field.

Metadata

Metadata

Assignees

Labels

Area-IDEBugFeature - IDE0044Make field readonlyResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions