Repository navigation
feat: the non-generic IComparable on every range union and RangeSet - #230
Merged
Merged
Conversation
The unions implemented IComparable<TRange> only, so List<IRange<T>>.Sort(), ArrayList.Sort() and Comparer.Default threw "At least one object must implement IComparable". IRangeFactory now also requires IComparable, and each of the 13 unions and RangeSet implements it explicitly, so the public surface keeps one CompareTo and EF Core still binds the generic one. It delegates to the same range order through RangeOrder.CompareObject: null sorts first, and an argument of another type throws ArgumentException naming both types. NonGenericComparableContractTests discovers every union, checks that the non-generic answer matches the generic one for every ordered shape pair of the range and of its RangeSet, that a foreign argument throws, and that List<IRange<T>> and ArrayList sort as Order() does; it fails with the interface removed and with a foreign argument ordered instead of refused. Closes #225 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #225
Stacked on #229 (#222): the new contract test uses that PR's
RangeCensusto show it reached every union. Merge #229 first; this PR's base then moves tomain.Problem
The range unions implemented
IComparable<TRange>(#39) but not the non-genericIComparable. SoList<IRange<int>>.Sort(),ArrayList.Sort()andComparer.Defaultthrew "At least one object must implement IComparable", although the docs sayList.Sort()works with no comparer.Change
IRangeFactory<TRange, T>also extendsIComparable. Each of the 13 unions implements it explicitly,int IComparable.CompareTo(object? other), and so doesRangeSet. The public surface keeps oneCompareTo, and EF Core still binds the generic one in a query.RangeOrder.CompareObject. It delegates to the same order:nullsorts first, as in the generic form. An argument that is not the same type throwsArgumentExceptionnaming both types ("Object must be of type Int32Range, not DecimalRange.").docs/ranges.md#sort-ranges: the sorting sentence now coversList<IRange<T>>andArrayList, and states theArgumentException. The multirange sentence namesIComparabletoo.Addedlines (root, core, NodaTime) now sayIComparable<TRange>andIComparable. This amends a 10.0.0 addition, so it adds no new line.Tests
NonGenericComparableContractTests(conventions, discovered). For every union, the non-genericCompareTogives the generic sign for every ordered pair of eight shapes, and likewise for their one-elementRangeSets plus{}. It is positive fornull. It throwsArgumentExceptionnaming the type for another range type, the element value and a string, and the set form throws for a range.List<IRange<T>>.Sort()andArrayList.Sort()sort asOrder()does.RangeCensusconfirms all 13 unions were reached.src/back atmain(no non-generic interface), it fails withEmptyRange does not implement the non-generic IComparable.The casts go throughobject, so the revert fails at run time rather than at compile time. With a foreign argument ordered (_ => 1) instead of refused, it fails withExpected exception of exact type ArgumentException.🤖 Generated with Claude Code