Skip to content

A base record's explicit Create from another project leaves two rule sets #195

Closed

Description

@CaffeinatedCoder

Package

CodoMetis.TypeKit.Generators

Version

2.3.0, and every release that generates validated value objects

How does it fail?

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

What you ran

A base record in another project implements IValidatedValue<TSelf, T, TFault>.Create explicitly; the value object declares its own public Create and reaches the marker only through the base:

// Library (no generators):
public abstract record StrictBase<TSelf> : IValidatedValue<TSelf, string, LibFault>
    where TSelf : StrictBase<TSelf>, IValidatedValue<TSelf, string, LibFault>
{
    static Result<TSelf, LibFault> IValidatedValue<TSelf, string, LibFault>.Create(string value) => Result.Error(LibFault.Refused);
}

// Consumer:
public sealed partial record Lenient : StrictBase<Lenient>
{
    public static Result<Lenient, LibFault> Create(string value) => new Lenient(value);
}

Lenient.TryFrom("x");     // Some: the value object's Create
CreateThrough<Lenient>("x");   // static T.Create(s), refused: the base's

What you got

Measured on release/2.4.0 at 97c87c1, 2026-10-30: two rule sets. Every generated way in calls Lenient.Create, which accepts; generic code calling T.Create reaches the base's explicit implementation, which refuses. ValueObjectDeclaration.CreateDeclarations reads the value object's own methods, and Metalama lists no private member of another assembly's type anyway. Declaring the marker on the value object as well (Lenient : StrictBase<Lenient>, IValidatedValue<Lenient, string, LibFault>) re-implements the interface and both agree. In the same project such a base carries the marker and is CMTK1022.

What you expected

CMTK1011, as for Create implemented explicitly on the value object beside a public one: one Create, public, implements the interface. Found by the interface mapping (TryFindImplementationForInterfaceMember), as #191's fix does. Reported from an outside review of #193.

Environment

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

Fixed in #193 (1e09f8d)

CreateDeclarations asks the interface mapping where T.Create lands. An explicit Create in a base record or an interface is CMTK1011, and so is a base's public Create beside the value object's own. The error says to declare the marker on the value object itself, which re-implements it. A base's public Create alone is one rule set and builds. Held by BuildOutcomeTests (LenientOverStrictBase, OnlyStrictBase, LenientOverPublicBase; building: LenientListedOverStrictBase, OnlyPublicBase), over a library the fixture builds without the generators. Decision 124 records it.

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 #201, merged into release/2.3.1 as 8fac39b; 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