Skip to content

Warning on Unused Record Primary Constructor Parameter #47666

@HaloFour

Description

@HaloFour

I was recently playing with positional records and overriding the property declarations, e.g.:

public record Person(string FirstName, string LastName) {
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

I was surprised to find that the constructor that is emitted in this case does not actually wire up the primary constructor parameters with the explicitly declared properties. I understand that this is because the implicit property declarations which are being overridden include an initializer which wires up the property.

In my opinion this would be an easy detail to miss and there is currently no indication that it's happening. I think it would be useful if the compiler would warn (or otherwise indicate) when the primary constructor parameter is unused.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions