Skip to content

fix: use range-aware shrinker in Int64Range to stay within bounds#92

Merged
untoldwind merged 1 commit into
leanovate:masterfrom
Yanhu007:fix/int-range-shrink-bounds
Apr 20, 2026
Merged

fix: use range-aware shrinker in Int64Range to stay within bounds#92
untoldwind merged 1 commit into
leanovate:masterfrom
Yanhu007:fix/int-range-shrink-bounds

Conversation

@Yanhu007
Copy link
Copy Markdown
Contributor

Fixes #81

Problem

gen.IntRange(min, max) uses the generic Int64Shrinker which shrinks toward 0. When the range doesn't include 0 (e.g., IntRange(5, 10)), the shrinker produces values outside the range during shrinking.

While the Sieve filters these out in some contexts, stateful command-based tests may not apply the sieve during the shrink phase, causing panics from out-of-bounds values.

Fix

Add a range-aware int64RangeShrinker(min, max) that shrinks toward min by halving the distance from min, guaranteeing all shrunk values stay within [min, max].

All existing tests pass with -race.

Int64Range used the generic Int64Shrinker which shrinks toward 0,
producing values outside the [min, max] range during shrinking.
While the Sieve filters these out, some property-based test
frameworks (like stateful commands) may not apply the sieve during
the shrink phase, causing panics from out-of-bounds values.

Add int64RangeShrinker that shrinks toward min by halving the
distance from min, guaranteeing all shrunk values stay within
[min, max].

Fixes leanovate#81
@untoldwind
Copy link
Copy Markdown
Collaborator

It might be a good idea to also "shrink" to the max value of the interval as the boundary condition might happen there.

@untoldwind untoldwind merged commit 967a500 into leanovate:master Apr 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getting values outside of range when using gen.IntRange (probably during shrink)

2 participants