Skip to content

Fix equals methods when comparing primitive range with ComparableRange #5475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edenman
Copy link

@edenman edenman commented Jul 25, 2025

In my codebase I added a helper method for working with Comparable that creates a range using T..T and I was surprised to see that my tests failed when I was asserting the values against a literal 1L..2L.

This PR fixes that behavior by checking if the other object is of type ClosedRange and then compares the interface fields directly. I couldn't get this to work for Short/Byte because the operator functions for those types return an IntRange (which cannot easily be coerced to/from a ComparableRange, etc). Open to suggestions on how/whether this can be fixed!

Also added a ReadMe to the generators/builtins folder because I couldn't figure out how to run those generators from the other ReadMe files.

Fixes KT-79598

In my codebase I added a helper method for working with Comparable<T>
that creates a range using T..T and I was surprised to see that my tests
failed when I was asserting the values against a literal 1L..2L.

This PR fixes that behavior by checking if the other object is of type
ClosedRange and then compares the interface fields directly.  I couldn't
get this to work for Short/Byte because the operator functions for those
types return an IntRange (which cannot easily be coerced to/from a
ComparableRange<Byte>, etc).  Open to suggestions on how/whether this
can be fixed!

Also added a ReadMe to the generators/builtins folder because I couldn't
figure out how to run those generators from the other ReadMe files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants