Skip to content

Wrong behavior when using records with primary constructors and inheritance? #48243

@Fabi

Description

@Fabi

In the latest .NET 5 preview I played around with records and noticed a for me unexpected behavior.

Given 2 records

record R1(int P1);
record R2 : R1(1);

This will result in
image
and
image

My expectation would have been that the old behavior of the first version of primary constructors would still work here.
Old behavior = It would call the constructor of R1 with the value 1 and creates R2 with the default ctor call.

Currently it seems that R2 that R1 got an empty constructor defined and R1 expects R2 to have an argument list that matches the given one.

record R1(int P1);
record R2(int P1) : R1(1);

would work but this actually doesn't make any sense for me.
And using an empty parameter list on R2 doesn't seem to be supported (why???)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions