You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CMTK0005: report ImmutableArray<T>.Builder.Count set on a builder of value objects #269
Found in the weaving review of #229, beside CollectionsMarshal.SetCount.
ImmutableArray<T>.Builder.Count = n grows the builder with default items whenever n is larger than its count, as CollectionsMarshal.SetCount(list, n) does for a List<T>, and CMTK0005 does not report it:
varbuilder=ImmutableArray.CreateBuilder<OrderId>();builder.Count=3;// three default OrderIds, nothing reportedvarids=builder.MoveToImmutable();
After #229 the Analyzers README's row says "an array, span or list ... given a length", which a reader takes to include this.
Proposal
CMTK0005 reports an assignment to ImmutableArray<T>.Builder.Count (resolved by symbol) where T is a value object, Option, Result or [RequireCustomInitialization] struct, unless the value is a constant zero. A Warning reporting more needs no exception to decision 34. Check the other BCL builders and lists with a settable count while there.
Test
A CMTK0005 row for the setter, a zero control, across TypeArgumentKinds.
Activity