Skip to content

fix: the non-generic CompareTo names a nested generic argument's type - #274

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/compareobject-type-name
Oct 19, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/compareobject-type-name

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #273
Part of #258 (part 1; part 2, the YearMonthRange exclusive infinity) load, is with the scheduling session)

Problem

RangeOrder.TypeName strips the generic arity at the backtick in Type.Name. A type nested inside a generic one, such as List<int>.Enumerator, is generic but its own name has no backtick. So ((IComparable)range).CompareTo(new List<int>().GetEnumerator()) threw ArgumentOutOfRangeException: length ('-1') must be a non-negative value instead of the intended ArgumentException naming both types. It still derived from ArgumentException, so the contract held, but the message was useless.

Change

TypeName strips the suffix only when the name has one. The message now reads Object must be of type Int32Range, not Enumerator<Int32>.

The PR hygiene check needs a closing keyword and #258 stays open for part 2, so part 1 became its own issue, #273, under the 10.0.0 epic. No changelog line: the non-generic CompareTo is new in this same 10.0.0.

Tests

  • NonGenericComparableContractTests adds a List<int>.Enumerator to the foreign arguments of every discovered union. It also checks that the message names the foreign type.
  • Proved by reverting. Without the guard it fails with Expected exception of exact type ArgumentException but caught ArgumentOutOfRangeException … length ('-1').
  • The unit and conventions tests pass.

🤖 Generated with Claude Code

RangeOrder.TypeName stripped the arity at the backtick of Type.Name, which a type nested in a
generic one does not have (List<int>.Enumerator is named "Enumerator"), so comparing a range with
one threw ArgumentOutOfRangeException ("length ('-1')") instead of the ArgumentException naming
both types. It now strips the suffix only when there is one.

NonGenericComparableContractTests adds a List<int>.Enumerator to the foreign arguments and checks
that the message names it; it fails with ArgumentOutOfRangeException without the guard.

Closes #273
Part of #258

Found-By: CA
Defect-Class: ALG
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 19, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working area/ranges Range unions, variants and the shape engines package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference labels Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ranges Range unions, variants and the shape engines bug Something isn't working package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-generic CompareTo's ArgumentException message breaks on a nested generic argument

1 participant