Skip to content

feat: CMTK0005 reports CollectionsMarshal.SetCount on a list of value objects - #271

Merged
CaffeinatedCoder merged 1 commit into
release/2.4.0from
feat/cmtk0005-set-count
Oct 31, 2026
Merged

CaffeinatedCoder merged 1 commit into
release/2.4.0from
feat/cmtk0005-set-count

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #229

Problem

CollectionsMarshal.SetCount(list, 3) on a List<OrderId> makes room for three items without putting one there, so the list holds three default value objects, as new OrderId[3] does. CMTK0005 covered arrays and spans only, so nothing reported it.

Change

  • DefaultFilledCollectionAnalyzer: resolves CollectionsMarshal.SetCount once per compilation and compares the call's OriginalDefinition to it by symbol. It reports where T is a value object, Option, Result or [RequireCustomInitialization] struct, unless the count is a constant zero (the existing Lengths and IsZero checks). A compilation without the method (before .NET 8) gets nothing new. The form in the message is CollectionsMarshal.SetCount.
  • Analyzers README: the CMTK0005 row now says "an array, span or list ... given a length", and the section has a sentence on SetCount. Only the CMTK0005 lines changed.
  • design/analyzers.md: the CMTK0005 row records the 2.4.0 reach. It is a Warning that reports more, so it stays within decision 34.
  • CHANGELOG 2.4.0 "Changed": one line.
  • test/oracles/claims.json: K05-a-list-given-a-count, which quotes the new README sentence and is held by DefaultFilledCollectionAnalyzerTests.

Tests

  • Setting_a_list_s_count_reports: the type argument inferred and written out, named arguments, Option, Result, [RequireCustomInitialization], a type parameter and a derived List<Plain>.
  • Setting_a_list_s_count_to_zero_or_of_another_type_stays_silent: 0, a named const, a named argument, (byte)0 and '\0', plus List<int>, List<Plain?> and a class value object.
  • The kinds theory now runs SetCount beside GC.AllocateArray over all 79 TypeArgumentKinds, and it reports exactly where the generic allocator does.
  • Counterfactuals: with the SetCount branch disabled, 6 tests fail (the row and the 5 reporting kinds). With the zero exemption disabled for SetCount, the control fails with 5 reports.
  • Through tools/BuildVerdict, locally:
    • Analyzers.Tests: 4031 passed.
    • Conventions.Tests: 2066 passed, the pack fixture included.
    • The full solution's remaining failures were all csc.dll exited with code 143 (SIGTERM) in consumer builds, with four parallel sessions loading the machine. That covers the Generators BuildOutcomeTests, which this change does not touch. CI's lanes are the clean run for those.

Weaving review: the change reads only §2 (one more creation form now covered), §3 (the BCL method is resolved by symbol; TypeKit discovery is unchanged) and §8 (a Warning, so decision 34's freeze does not apply). The review turned up two neighbours, filed for 2.4.0: #269 (ImmutableArray<T>.Builder.Count) and #270 (Array.Clear, Span<T>.Clear).

🤖 Generated with Claude Code

… objects

CollectionsMarshal.SetCount(list, n) on a List<OrderId> makes room for n
items without putting one there, as new OrderId[n] does, and nothing
reported it. CMTK0005 now reports it where the element is a value
object, Option, Result or [RequireCustomInitialization] struct, unless
the count is a constant zero. The method is resolved by symbol, once per
compilation, and compared through OriginalDefinition; a compilation
without it (before .NET 8) registers nothing new.

Input class: AIS, what a type argument is. The kinds theory now runs
SetCount beside GC.AllocateArray over TypeArgumentKinds (79 kinds): it
reports exactly where the generic allocator does. The rows cover the
type argument inferred and written, named arguments, Option, Result,
[RequireCustomInitialization], a type parameter and a derived list; the
zero control covers 0, a named const, a named argument, (byte)0 and
'\0', with List<int>, List<Plain?> and a class value object silent.
Seeding the branch off turns 6 tests red; seeding the zero exemption
off turns the control red with 5 reports.

Neighbours found in the weaving review, filed for 2.4.0: #269
(ImmutableArray<T>.Builder.Count) and #270 (Array.Clear, Span<T>.Clear).

Closes #229

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added this to the 2.4.0 milestone Oct 31, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request package/analyzers Affects CodoMetis.TypeKit.Analyzers area/value-objects Value-object contracts and what the aspects generate for them labels Oct 31, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 09ec900 into release/2.4.0 Oct 31, 2026
14 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/cmtk0005-set-count branch October 31, 2026 20:15
CaffeinatedCoder added a commit that referenced this pull request Oct 31, 2026
Brings #271 (CMTK0005 SetCount) and #274 (CI tests by reach). Both
changelog lines are kept, CMTK0005's before CMTK0009's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 enhancement New feature or request package/analyzers Affects CodoMetis.TypeKit.Analyzers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant