dotnet/roslyn

DebuggerDisplay fails when access properties in records

开放

#48,469 创建于 2020年10月9日

 (2 条评论) (0 个反应) (0 位负责人)C# (4,257 个派生)batch import
Area-InteractiveBugFeature - Recordshelp wanted

仓库指标

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

描述

Version Used:

  • 5.0.100-rc.1.20452.10

Steps to Reproduce:

public class Program
{
    public static void Main()
    {
        var me = new Person("Phil", "Scott");
        var meWithAccessors = new PersonWithAccessors("Phil", "Scott");
        var meWithMethod = new PersonWithMethod("Phil", "Scott");

        Console.WriteLine("Hello World!");
    }

    [DebuggerDisplay("{FirstName} {LastName}")]
    record Person(string FirstName, string LastName);

    [DebuggerDisplay("{get_FirstName()} {get_LastName()}")]
    record PersonWithAccessors(string FirstName, string LastName);

    [DebuggerDisplay("{GetName(), nq}")]
    record PersonWithMethod(string FirstName, string LastName)
    {
        public string GetName() => $"{FirstName} {LastName}";
    }
}

Expected Behavior:

"Phil Scott" to be display for all three. Well, maybe not the one where I'm going directly to get accessors.

Actual Behavior:

Accesssing via the accessors and a method works fine, but receive the error Property, indexer, or event 'Program.Person.FirstName' is not supported by the language; try directly calling accessor methods 'Program.Person.get_FirstName()' or 'Program.Person.set_FirstName(?)' Property, indexer, or event 'Program.Person.LastName' is not supported by the language; try directly calling accessor methods 'Program.Person.get_LastName()' or 'Program.Person.set_LastName(?)' when going directly to the properties.

贡献者指南