dotnet/roslyn

DebuggerDisplay fails when access properties in records

Open

#48,469 opened on Oct 9, 2020

View on GitHub
 (2 comments) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-InteractiveBugFeature - Recordshelp wanted

Description

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.

Contributor guide

DebuggerDisplay fails when access properties in records · dotnet/roslyn#48469 | Good First Issue