Skip to content

C# 9 Records: Explicit property declaration breaks primary constructor #48584

@albahari

Description

@albahari

Version Used: 3.8.0-3.20458.6

Steps to Reproduce:

Run the following code:

Console.WriteLine (new Test(1).X == 1);

record Test (int X)
{
    int _x;
    public int X { get => _x; init => _x = value; }
}

Expected Behavior:

This should print "True"

Actual Behavior:

It prints "False"

The auto-generated constructor fails to set the X property.

Metadata

Metadata

Assignees

Labels

4 - In ReviewA fix for the issue is submitted for review.Area-CompilersBugConcept-Diagnostic ClarityThe issues deals with the ease of understanding of errors and warnings.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions