Repository navigation
fix: CMTK0005 reports Array.CreateInstance, CreateInstanceFromArrayType and ArrayPool<T>.Rent - #235
Open
CaffeinatedCoder wants to merge 3 commits into
Open
CaffeinatedCoder wants to merge 3 commits into
CaffeinatedCoder wants to merge 3 commits into
Conversation
…pe and ArrayPool<T>.Rent AnalyzeInvocation looked only at generic calls with one type argument, GC.AllocateArray, GC.AllocateUninitializedArray and Array.Resize. The README defines CMTK0005 as an array of a value object created with a length, which Array.CreateInstance(typeof(Plain), 3) in each overload, CreateInstanceFromArrayType(typeof(Plain[]), 3) and ArrayPool<Plain>.Shared.Rent(3) are too; none was reported. The two factories are reported when a typeof names the element (the element of the array type for the second); a Type in a variable could be anything and stays silent. Rent is recognised on ArrayPool<T> or an override of it, its T the element. The lengths are read from every int or long parameter and the elements of a params or written-out array of them, never the lower bounds, so #227's rule holds: a constant zero in any dimension stays silent. Input class (AIS): an expression that creates an array of a no-default struct, by the API that creates it. Every Array.CreateInstance and CreateInstanceFromArrayType overload that takes a length, Rent on the shared pool, on ArrayPool<T>.Create() and on a derived pool, each with a zero-length control; a Type variable, GetType(), typeof(Plain?) and an array of another element silent. Rent's T and the typeof element run across TypeArgumentKinds (79 kinds; dynamic and string? take Rent alone, typeof refusing them): each reports exactly where GC.AllocateArray<K> does. No sibling beyond #229's CollectionsMarshal.SetCount, which 2.4.0 takes. Reverting the source fails the forms row and the three kinds that report. Seeding the zero check away fails the three zero rows, reading the lower bounds as lengths fails the forms row, and skipping an array of lengths fails the silent row. Closes #228 Defect-Class: AIS Found-By: RS Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from
fix/zero-dimension-array-silent-2-3-1
to
release/2.3.1
October 31, 2026 07:48
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
This branch has not been deployed
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 #228
Stacked on #233 (#227), which changes the same file: merge #233 first, then retarget this to
release/2.3.1.Problem
DefaultFilledCollectionAnalyzer.AnalyzeInvocationlooked only at generic calls with one type argument (GC.AllocateArray,GC.AllocateUninitializedArray,Array.Resize).Array.CreateInstance(typeof(Plain), 3)(one to three dimensions,params int[],params long[], with lower bounds),Array.CreateInstanceFromArrayType(typeof(Plain[]), 3)andArrayPool<Plain>.Shared.Rent(3)create the same default slots and got nothing.Change
DefaultFilledCollectionAnalyzer.cs: the two factories are reported when atypeofnames the element (forCreateInstanceFromArrayType, the element of the array type); aTypein a variable stays silent.Rentis recognised onArrayPool<T>or an override of it,Tthe element. OneLengthsreads everyint/longlength parameter and the elements of aparamsor written-out array of them, neverlowerBounds, so CMTK0005 reports a multidimensional array with a zero dimension, such as new Plain[0, 2], which holds no element #227's rule holds for every form: a constant zero in any dimension stays silent.Typevariable isn't reported; claimK05-a-factory-given-a-typeofholds it.Tests
The_array_factories_and_the_pool_report: everyCreateInstance/CreateInstanceFromArrayTypeoverload that takes a length,Renton the shared pool, onArrayPool<T>.Create()and on a derived pool, anOption<int>element and atypeof(T)of a constrained parameter.The_array_factories_with_a_zero_length_or_an_unknown_type_stay_silent: a zero-length control for each form (in each dimension, in aparamslist, beside lower bounds,long), aTypevariable,GetType(),typeof(Plain?),typeof(int),typeof(Plain[]),ArrayPool<int>andActivator.CreateInstance.The_factories_judge_each_kind_as_the_generic_allocator_does:Rent'sTand thetypeofelement acrossTypeArgumentKinds(79 kinds); each reports exactly whereGC.AllocateArray<K>does, with a value-object struct as the positive control and a compile-error check so no row passes vacuously.tools/BuildVerdict.CollectionsMarshal.SetCountis #229 (2.4.0) and out of scope.🤖 Generated with Claude Code