Positional records bug? Parent class has positional member, child doesn't, gives syntax error #3795
-
It seems there's something weird going on when a base positional record has a member, and a derived record attempts to pass a value and doesn't have any positional members of its own. public record Base(string S) { }
public record Derived : Base("S") { }
// ~~~~~~~ ~
// | |
// | error CS8861: Unexpected argument list.
// error CS1729: 'Base' does not contain a constructor that takes 0 arguments Giving the derived type any positional members fixes the issue: public record Base(string S) { }
public record Derived(string T) : Base("S") { }
// No errors |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
From the specification:
I do not recall why this limitation was introduced, but the behavior you're seeing is the design. You would need to instead do something like public record Base(string S) { }
public record Derived : Base
{
public Derived() : base("S") { }
} |
Beta Was this translation helpful? Give feedback.
-
@agocke I saw that you have introduced this change: https://github.com/dotnet/csharplang/pull/3527/files#diff-584f61a480e3d35cb05945dcd5be8e3eR28 For sure there is a good reason, that I cannot understand, could you explain us the rationale behind this restriction? |
Beta Was this translation helpful? Give feedback.
-
@andresmoschini LDM already made the decision to allow an empty parameter list, but the spec hasn't been updated yet. It's already allowed in master. (Done in #3900) |
Beta Was this translation helpful? Give feedback.
-
Thanks @PathogenDavid! your answer is very useful for me to learn were to read. |
Beta Was this translation helpful? Give feedback.
From the specification:
I do not recall why this limitation was introduced, but the behavior you're seeing is the design. You would need to instead do something like