The following prints True rather than False because the synthesized bool Equals(B other) method does not compare inherited fields from the non-record base type.
```C#
class A
{
internal A(int X) { this.X = X; }
internal int X { get; set; }
}
record B(int X, int Y) : A(X)
{
}
class Program
{
static void Main()
{
System.Console.WriteLine(new B(0, 2).Equals(new B(1, 2)));
}
}
```
IMO a record that inherits from a non-record shouldn't make assumptions regarding how equality should be calculated for the base class. I suggest calling base.Equals and base.GetHashCode, unless those methods are not overridden by any type in the hierarchy and would result in a call to object.Equals or object.GetHashCode, in which case the compiler could elide the base call. This is how Scala handles equality with case classes that inherit from non-case classes and it works pretty well.
Records can only inherit from other records or System.Object.
This can be re-opened and semantics explored if we decide to lift that restriction
@agocke @cston
Out of curiosity, how will the compiler recognize that the base type is a "record"?
At the moment, because the design happens to generate a clone method called <>Clone, we use its presence to indicate a record.
Most helpful comment
IMO a record that inherits from a non-record shouldn't make assumptions regarding how equality should be calculated for the base class. I suggest calling
base.Equalsandbase.GetHashCode, unless those methods are not overridden by any type in the hierarchy and would result in a call toobject.Equalsorobject.GetHashCode, in which case the compiler could elide the base call. This is how Scala handles equality with case classes that inherit from non-case classes and it works pretty well.