Skip to content

A hand-written Equals(TBase) on a value object is kept, and a collection of the base compares by it #196

Closed

Description

@CaffeinatedCoder

Package

CodoMetis.TypeKit.Generators

Version

2.3.0, and every release that generates equality over a base record

How does it fail?

Silently. It compiles or answers, and does less than it appears to

What you ran

A value object over a base record declares an Equals for one of its base types:

public abstract record DeepBase;
public abstract record MiddleBase : DeepBase;

public sealed partial record Tag : MiddleBase, IValue<string>
{
    public bool Equals(DeepBase? other) => ReferenceEquals(this, other);
}

Tag.From("a") == Tag.From("a");                              // true
new HashSet<DeepBase> { Tag.From("a"), Tag.From("a") }.Count;  // 2
new HashSet<Tag> { Tag.From("a"), Tag.From("a") }.Count;       // 1

What you got

Measured on release/2.4.0 at 97c87c1, 2026-10-30. ValueObjectDeclaration.EqualityDeclaredByHand refuses Equals(TSelf), GetHashCode() and an explicit IEquatable<TSelf>.Equals, and reads no Equals(TBase). The hand-written one implements IEquatable<DeepBase> (re-listed through IReimplementedEquatable<DeepBase>), and ValueObjectContractAspect.IntroduceEquality skips its own new Equals(TBase) when the value object declares one, so a collection of the base compares by reference while the value object's equality is its wrapped value's.

What you expected

CMTK1011, as for a hand-written Equals(TSelf): a value object's equality is its wrapped value's. Reported from an outside review of #193.

Environment

.NET SDK 10.0.4xx, Metalama 2026.1; any consumer.

Activity

  1. added this to the 2.4.0 milestone on Oct 30, 2026
  2. added
    bugSomething isn't working
    silentCompiles or answers and does less than it appears to
    severity/mediumInconsistency or failure in a narrow scenario
    package/generatorsAffects CodoMetis.TypeKit.Generators
    area/value-objectsValue-object contracts and what the aspects generate for them
    on Oct 30, 2026
  3. modified the milestones: 2.4.0, 2.3.1 on Oct 30, 2026
  4. CaffeinatedCoder commented on Oct 30, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Fixed by #202, merged into release/2.3.1 as 70e3d8b; ships in 2.3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/value-objectsValue-object contracts and what the aspects generate for thembugSomething isn't workingpackage/generatorsAffects CodoMetis.TypeKit.Generatorsseverity/mediumInconsistency or failure in a narrow scenariosilentCompiles or answers and does less than it appears to

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions