dotnet/roslyn

Debugger fails to expand ref members in the same way it expands pointer members.

开放

#57,220 创建于 2021年10月18日

 (3 条评论) (0 个反应) (0 位负责人)C# (4,257 个派生)batch import
Area-InteractiveConcept-Continuous Improvementhelp wanted

仓库指标

星标
 (20,414 个星标)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

C# 10 Steps to Reproduce:

Consider this code (a bit contrived but it shows the problem)

namespace ConsoleApp38
{
    internal class Program
    {

        static void Main(string[] args)
        {
            Demo demo = new Demo();

            demo.Ref.f0 = 123;
        }
    }

    public unsafe struct Demo
    {
        private readonly Fields * fields;

        public Demo()
        {
            // Just allocate some memory so we can write to it
            fields = (Fields*)Marshal.AllocHGlobal(sizeof(Fields));
            fields->f0 = 0;
            fields->f1 = 0;
        }

        public Fields * Ptr { get { return fields; } }

        public ref Fields Ref { get { return ref (*fields); } }
    }

    public struct Fields
    {
        public int f0;
        public double f1;
    }
}

Expected Behavior:

When debugged with a break on the line that assigns 123 to f0, we can see in the Locals window that demo can be expanded as can Ptr (but not Ref).

Actual Behavior:

The debugger does not let us 'expand' the 'ref', which is a ref return property.

If you execute the line you can also see that the structs fields f0 is updated via the ref, so we can clearly see that the ref and ptr are valid values.

I'm regarding this as a bug but there may be more to this...

贡献者指南