Allow derived record members with covariant properties #9030
Answered
by
CyrusNajmabadi
alrz
asked this question in
Language Ideas
-
Currently record properties of the base type must be of the exact same type: abstract record R(object Prop);
sealed record R1(string Prop) : R(Prop);
// error CS8866: Record member 'R.Prop' must be a readable instance property or field of type 'string' to match positional parameter 'Prop'. But the compiler could use covariant return types to allow this: abstract class R
{
public abstract object Prop { get; }
}
sealed class R1(string Prop) : R
{
public override string Prop { get; } = Prop;
} |
Beta Was this translation helpful? Give feedback.
Answered by
CyrusNajmabadi
Jan 8, 2025
Replies: 1 comment 2 replies
-
I don't understand how this would work. What would the following compile down to: |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
alrz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't understand how this would work. What would the following compile down to:
R r = new R1(); r with { Prop = 4 }
?