Fix Range.disjoint?/2 for single-element ranges with a negative step#15582
Merged
josevalim merged 1 commit intoJul 10, 2026
Merged
Conversation
`member?/2`, `size/1` and `to_list/1` all treat a single-element range
such as `1..1//-2` as the set `[1]`, and `Range.split/2` produces such
ranges from library code (e.g. `Range.split(5..1//-2, 2)` yields
`1..1//-2`). Yet `disjoint?/2` reported two of them as sharing no
element:
Range.disjoint?(1..1//-2, 1..1//-2) #=> true (should be false)
`normalize/3` only reversed ranges when `first > last`, leaving a
negative step in place for single-element ranges (`first == last`). The
arithmetic-progression intersection in `disjoint?/2` assumes an
increasing progression, so the leftover negative step produced a wrong
result. The `step == -1` case was masked by the `abs(step) == 1`
shortcut, so only `step <= -2` was affected.
Assisted-by: Claude Code:claude-opus-4-8
Member
|
💚 💙 💜 💛 ❤️ |
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.
member?/2,size/1andto_list/1all treat a single-element range such as1..1//-2as the set[1], andRange.split/2produces such ranges from library code (e.g.Range.split(5..1//-2, 2)yields1..1//-2). Yetdisjoint?/2reported two of them as sharing no element:normalize/3only reversed ranges whenfirst > last, leaving a negative step in place for single-element ranges (first == last). The arithmetic-progression intersection indisjoint?/2assumes an increasing progression, so the leftover negative step produced a wrong result. Thestep == -1case was masked by theabs(step) == 1shortcut, so onlystep <= -2was affected.Assisted-by: Claude Code:claude-opus-4-8