Skip to content

Commit 18aa75f

Browse files
Fix method ambiguity error of shuffle! with AbstractArray{Bool} on Julia 1.11 (#24)
Co-authored-by: Eric Hanson <[email protected]>
1 parent 7e5c4a8 commit 18aa75f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/StableRNGs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ end
141141

142142
# https://github.com/JuliaRandom/StableRNGs.jl/issues/10
143143
Random.shuffle(r::StableRNG, a::AbstractArray) = Random.shuffle!(r, Base.copymutable(a))
144-
function Random.shuffle!(r::StableRNG, a::AbstractArray)
144+
# Fix method ambiguity issue: https://github.com/JuliaRandom/StableRNGs.jl/issues/23
145+
Random.shuffle!(r::StableRNG, a::AbstractArray) = _shuffle!(r, a)
146+
Random.shuffle!(r::StableRNG, a::AbstractArray{Bool}) = _shuffle!(r, a)
147+
function _shuffle!(r::StableRNG, a::AbstractArray)
145148
require_one_based_indexing(a)
146149
n = length(a)
147150
n <= 1 && return a # nextpow below won't work with n == 0

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ end
139139
b = collect(a)
140140
shuffle!(StableRNG(10), b)
141141
@test b == a_shuffled
142+
143+
# https://github.com/JuliaRandom/StableRNGs.jl/issues/23
144+
c = [false, true, false, true, false]
145+
c_shuffled = [false, false, false, true, true]
146+
@test shuffle!(StableRNG(123), c) == c_shuffled
147+
d = [false true; true false]
148+
d_shuffled = [true true; false false]
149+
@test shuffle(StableRNG(31), d) == d_shuffled
142150
end
143151

144152
# https://github.com/JuliaRandom/StableRNGs.jl/issues/20

0 commit comments

Comments
 (0)