Skip to content

🐛 Fix SequenceSet#[] with valid positive range.begin but invalid negative range.end - #776

Open
nevans wants to merge 1 commit into
sequence_set/fix-slice-when-start-at-starfrom
sequence_set/fix-slice-range-pos-to-out-of-range-neg
Open

nevans wants to merge 1 commit into
sequence_set/fix-slice-when-start-at-starfrom
sequence_set/fix-slice-range-pos-to-out-of-range-neg

Conversation

@nevans

@nevans nevans commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

When slicing with a positive..negative range, where the range ends prior to the beginning of the set, SequenceSet#slice incorrectly set max to the last value in the set, without regarding the sign of the range end. This converted both set[first..last] and set[first..-last] into set[first..] when the range end is out of range, which is correct for positive range end, but clearly incorrect for negative range end.

This PR fixes that, by treating a missing negative max as 0, e.g: identical to set[first...0]. Assuming first.abs <= cardinality, this will return an empty set.

@nevans nevans added the bug Something isn't working label Oct 3, 2026
@nevans
nevans added this pull request to stack #775 October 3, 2026 00:33
@nevans nevans added the backport-0.5 This ticket needs to be backported to the v0.5-stable branch. label Oct 3, 2026
When slicing with a positive...negative range, where the range ends
prior to the beginning of the set, this incorrectly set `max` to the
_last_ value in the set, without regarding the sign of the range end.
This converts both `set[start..end]` and `set[start..-end]` into
`set[start..]` when the range end is out of range, which is correct for
positive range end, but clearly incorrect for negative range end.
@nevans
nevans force-pushed the sequence_set/fix-slice-range-pos-to-out-of-range-neg branch from ada5632 to b546855 Compare October 3, 2026 13:42
@nevans nevans changed the title 🐛 Fix SequenceSet#slice(pos..too_low_neg) 🐛 Fix SequenceSet#[] for range with valid positive begin, but invalid negative end Oct 3, 2026
@nevans nevans changed the title 🐛 Fix SequenceSet#[] for range with valid positive begin, but invalid negative end 🐛 Fix SequenceSet#[] with valid positive range.begin but invalid negative range.end Oct 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-0.5 This ticket needs to be backported to the v0.5-stable branch. bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant