Skip to content

CMTK0005: report Array.Clear and Span<T>.Clear on value objects #270

Open

Description

@CaffeinatedCoder

Found in the weaving review of #229.

Array.Clear and Span<T>.Clear() set existing slots back to default, which CMTK0001 does not see since no default is written, and CMTK0005 does not report since nothing is created:

OrderId[] ids = [.. rows.Select(r => OrderId.From(r.Id))];
Array.Clear(ids);                        // every slot now a default OrderId, nothing reported
ids.AsSpan().Clear();                    // the same

Array.Fill(ids, default) and span.Fill(default) are already caught by CMTK0001, since they write default.

Proposal

CMTK0005 reports Array.Clear (each overload) and Span<T>.Clear() where the element is a value object, Option, Result or [RequireCustomInitialization] struct, unless a constant length of zero is given; resolved by symbol. The README's row then names clearing beside creating. A Warning reporting more needs no exception to decision 34. Whether this belongs in CMTK0005 (whose title is a collection "filled with default instances") or in a rule of its own is part of the decision.

Test

A CMTK0005 row per overload, a zero-length control, across TypeArgumentKinds.

Activity

  1. added this to the 2.4.0 milestone on Oct 31, 2026
  2. added
    enhancement
    package/analyzers
    area/value-objects
    on Oct 31, 2026
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-objectsenhancementpackage/analyzers

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions