Skip to content

fix: CMTK0005 stays silent on an array with a constant zero in any dimension - #233

Merged
CaffeinatedCoder merged 2 commits into
release/2.3.1from
fix/zero-dimension-array-silent-2-3-1
Oct 31, 2026
Merged

CaffeinatedCoder merged 2 commits into
release/2.3.1from
fix/zero-dimension-array-silent-2-3-1

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Closes #227

Problem

DefaultFilledCollectionAnalyzer.AnalyzeArrayCreation skipped an array only when every dimension was a constant 0. A multidimensional array is empty when any dimension is, so new Plain[0, 2] and new Plain[2, 0], which hold no element, got CMTK0005.

Change

  • DefaultFilledCollectionAnalyzer.cs: Any in place of All for the array creation; the stackalloc path reads the same rule (one dimension there, so no behaviour change).
  • Analyzers README: the CMTK0005 row and section say a zero in any one dimension isn't reported; claim K05-a-zero-dimension-is-silent holds the new sentence.
  • Sibling (Found-By: VA, its own commit): the zero check matched only a boxed int, so new Plain[0L], [0u, 2], [2, 0ul] and stackalloc Plain[(byte)0], [(short)0], ['\0'] were reported. One IsZero now reads every integral constant, for the array creation, the stackalloc and the allocating calls.
  • CHANGELOG: a line under 2.3.1, in a new ### Fixed. A Warning that reports less needs no exception to decision 34.

Tests

  • DefaultFilledCollectionAnalyzerTests.An_array_with_any_constant_zero_dimension_stays_silent, across the input class (an array creation, by rank and by which dimension is a constant zero): [0, 2], [2, 0], [0, 0], [n, 0], [none, n] (a named constant), [2, 0, 2], [n, 2, 0] and a jagged [0][] silent; [2, 2] and [n, 1, 2] reported.
  • Reverting the source fails it: 8 reports where 2 are expected.
  • A_zero_of_any_integral_type_stays_silent: the zero written as int, long, uint, ulong, byte, short and char, in new, stackalloc, GC.AllocateArray and Array.Resize; [1L] and stackalloc [(byte)1] reported. Seeding the int-only match back fails it: 8 reports where 2 are expected.
  • Analyzers (3,690), Conventions (2,016), Samples (150) and Oracles (51) green locally through tools/BuildVerdict.

🤖 Generated with Claude Code

…mension

AnalyzeArrayCreation skipped an array only when every dimension was a
constant 0. A multidimensional array is empty when any one dimension is,
so new Plain[0, 2] held no default element and was reported. The check
is now Any; stackalloc reads the same rule, where its one dimension made
All and Any agree already.

Input class (AIS): an array creation of a no-default struct, by rank and
by which dimension is a constant zero. The new row covers rank 2 with
the first, the second and both dimensions zero, a variable beside a
literal zero and a named constant beside a variable, rank 3 with a zero
in the middle and last, a jagged [0][], and two arrays with no zero
dimension that still report. No sibling: the invocation forms take one
length, where a zero is already skipped.

Reverting the source fails the row: 8 reports where 2 are expected.

Closes #227

Defect-Class: AIS
Found-By: OR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added this to the 2.3.1 milestone Oct 31, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working severity/low Cosmetic, message or documentation-level difference package/analyzers Affects CodoMetis.TypeKit.Analyzers area/value-objects Value-object contracts and what the aspects generate for them labels Oct 31, 2026
The zero check matched only a boxed int. An array dimension may be a
long, uint or ulong, so new Plain[0L] was reported, and a stackalloc
size is read from syntax with its type before the conversion to int,
so stackalloc Plain[(byte)0], [(short)0] and ['\0'] were too. One
IsZero now reads every integral constant, for the array creation, the
stackalloc and the allocating calls alike.

Found running #227's input class (an array creation by which dimension
is a constant zero) across how the zero is written: int, long, uint,
ulong, byte, short and char, in new, stackalloc, GC.AllocateArray and
Array.Resize. The six that failed are the long and unsigned dimensions
and the three stackalloc sizes.

Seeding the int-only match back fails the row: 8 reports where 2 are
expected.

Refs #227

Defect-Class: AIS
Found-By: VA
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 bug Something isn't working package/analyzers Affects CodoMetis.TypeKit.Analyzers severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant