Repository navigation
feat: CMTK0005 reports CollectionsMarshal.SetCount on a list of value objects - #271
Merged
Merged
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #229
Problem
CollectionsMarshal.SetCount(list, 3)on aList<OrderId>makes room for three items without putting one there, so the list holds three default value objects, asnew OrderId[3]does. CMTK0005 covered arrays and spans only, so nothing reported it.Change
DefaultFilledCollectionAnalyzer: resolvesCollectionsMarshal.SetCountonce per compilation and compares the call'sOriginalDefinitionto it by symbol. It reports whereTis a value object,Option,Resultor[RequireCustomInitialization]struct, unless the count is a constant zero (the existingLengthsandIsZerochecks). A compilation without the method (before .NET 8) gets nothing new. The form in the message isCollectionsMarshal.SetCount.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.test/oracles/claims.json:K05-a-list-given-a-count, which quotes the new README sentence and is held byDefaultFilledCollectionAnalyzerTests.Tests
Setting_a_list_s_count_reports: the type argument inferred and written out, named arguments,Option,Result,[RequireCustomInitialization], a type parameter and a derivedList<Plain>.Setting_a_list_s_count_to_zero_or_of_another_type_stays_silent:0, a named const, a named argument,(byte)0and'\0', plusList<int>,List<Plain?>and a class value object.SetCountbesideGC.AllocateArrayover all 79TypeArgumentKinds, and it reports exactly where the generic allocator does.SetCountbranch disabled, 6 tests fail (the row and the 5 reporting kinds). With the zero exemption disabled forSetCount, the control fails with 5 reports.tools/BuildVerdict, locally:csc.dll exited with code 143(SIGTERM) in consumer builds, with four parallel sessions loading the machine. That covers the GeneratorsBuildOutcomeTests, 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