Skip to content

fix: refuse a value-object contract declared through an interface or a base record - #204

Merged
CaffeinatedCoder merged 1 commit into
release/2.3.1from
fix/value-object-contract-through-interface-refused-2-3-1
Oct 30, 2026
Merged

CaffeinatedCoder merged 1 commit into
release/2.3.1from
fix/value-object-contract-through-interface-refused-2-3-1

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #192

Problem

public interface IEntityId<TSelf> : IValueObject<TSelf, Guid> where TSelf : IEntityId<TSelf>;

public readonly partial record struct OrderId : IValue<Guid>, IEntityId<OrderId>;
// LAMA0512: The aspect 'ValueObjectContractAspect' cannot implement interface 'IValueObject<OrderId, Guid>' ...

The generators implement IValueObject<,>, IValueObjectMaterializer<,> and IPlainValueObject<,> with OverrideStrategy.Fail, and declaring one on the value object is CMTK1011. Declared any other way, the aspect failed with a Metalama error that names nothing the user wrote. That covers an interface of the user's (one interface down or two, this project or another) and a base record. The errors were LAMA0512, plus LAMA0041 for the materializer. ValueObjectDeclaration.GeneratedMembersDeclaredByHand read only the interfaces the value object declares directly.

Change

  • GeneratedMembersDeclaredByHand now also reads each declared interface's own interfaces, and each base record's interfaces. It names where the contract comes from: "the interface IValueObject<OrderId, Guid> in its interface IEntityId", or "… in its base type X". IConvertible is folded into the same check, with unchanged messages.
  • Neither marker (IValue<T>, IValidatedValue<,,>) derives from a contract, so an interface derived from a marker stays allowed.
  • Only builds that failed before fail, now with CMTK1011 instead of a Metalama error.
  • Decision 121 is widened. It records refusing over accepting the contract through an interface, which the generated Value would implement: that would add behaviour to a patch, for a constraint IValueObject<TSelf, T> itself serves.
  • The Generators README's "Write your own members" now names the three contracts and says to constrain generic code on IValueObject<TSelf, T>. That sentence was already promising "declared directly or through another interface". Claim C22-a-contract-through-an-interface holds it. The 2.3.1 changelog and design/aspects.md follow.

Tests

BuildOutcomeTests (294):

  • Six rows in An_interface_s_explicit_implementation_of_a_generated_interface_is_refused_by_name. IValueObject one and two interfaces down, through a base record's interface, and through a library interface (the fixture's generator-free library). IValueObjectMaterializer and IPlainValueObject through an interface.
  • A_marker_declared_through_an_interface_is_generated pins that a marker-derived interface still builds.

Reverted (verify-the-guard):

Seed Fails
The source back to release/2.3.1 8: the 6 new rows, plus Every_error_is_one_of_the_intended_ones and Nested_value_objects_... (LAMA)
Skip the interfaces' own interfaces 9: the 5 contract rows through an interface, the 2 IConvertible ones, plus the LAMA guards
Skip the base records 6: ContractThroughBaseInterface, the 3 IConvertible base rows, plus the LAMA guards
Count the marker as a contract the build: every value object in Probes is refused

Variants. Input class GTS: a contract the generators implement, by where it's declared (the value object, an interface one or two down, a library's interface, a base record) and which contract.

🤖 Generated with Claude Code

…a base record

IValueObject<,>, IValueObjectMaterializer<,> and IPlainValueObject<,>
are implemented by the generators with OverrideStrategy.Fail, and
declaring one on the value object is CMTK1011. Declared through an
interface of the user's, as an IEntityId<TSelf> : IValueObject<TSelf,
Guid> written to constrain generic code, or by a base record, the
aspect failed instead (LAMA0512, and LAMA0041 for the materializer),
naming nothing the user wrote: GeneratedMembersDeclaredByHand read the
value object's directly declared interfaces alone.

It now reads each declared interface's own interfaces and each base
record's, and names where the contract comes from ("the interface
IValueObject<OrderId, Guid> in its interface IEntityId<OrderId>", "...
in its base type X"), with IConvertible folded into the same check.
Neither marker derives from a contract, so an interface derived from a
marker stays allowed. Only builds that failed before fail, now with a
CMTK error. Decision 121 records refusing over accepting the contract
through an interface, which would add behaviour to a patch.

Input class (GTS): a contract the generators implement, by where it is
declared. Catalogue: IValueObject one and two interfaces down, through a
base record's interface and through a library interface;
IValueObjectMaterializer and IPlainValueObject through an interface; and
an interface derived from the marker, which builds. IConvertible's rows
hold the folded check.

Reverting the source fails the 6 new rows and the two LAMA guards (8 of
294 BuildOutcomeTests); dropping the interface or the base read fails
its rows; counting the marker as a contract refuses every value object.

Refs #192

Defect-Class: GTS
Found-By: VA
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 2.3.1 milestone Oct 30, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working severity/low Cosmetic, message or documentation-level difference package/generators Affects CodoMetis.TypeKit.Generators area/value-objects Value-object contracts and what the aspects generate for them labels Oct 30, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit dbdd44e into release/2.3.1 Oct 30, 2026
14 of 15 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/value-object-contract-through-interface-refused-2-3-1 branch October 30, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/value-objects Value-object contracts and what the aspects generate for them bug Something isn't working package/generators Affects CodoMetis.TypeKit.Generators severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant