Skip to content

Commit 71899e8

Browse files
committed
Pair API: allow any type of Pair
Do not restrict the first argument to be a `DataType`/`UnionAll`, as `make` is about to start accepting non-type objects as first argument.
1 parent c15362d commit 71899e8

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/sampling.jl

+4-6
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,10 @@ pair_to_make((a, b)::Pair) =
574574

575575
pair_to_make(x) = x
576576

577-
@inline Sampler(RNG::Type{<:AbstractRNG}, p::Pair{<:Union{DataType,UnionAll}},
578-
r::Repetition) =
579-
Sampler(RNG, pair_to_make(p), r)
577+
@inline Sampler(RNG::Type{<:AbstractRNG}, p::Pair, r::Repetition) =
578+
Sampler(RNG, pair_to_make(p), r)
580579

581580
# nothing can be inferred when only the pair type is available
582-
@inline gentype(::Type{<:Pair{<:Union{DataType,UnionAll}}}) = Any
581+
@inline gentype(::Type{<:Pair}) = Any
583582

584-
@inline gentype(p::Pair{<:Union{DataType,UnionAll}}) =
585-
gentype(pair_to_make(p))
583+
@inline gentype(p::Pair) = gentype(pair_to_make(p))

test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ end
570570
@testset "rand(T => x) & rand(T => (x, y, ...))" begin
571571
@test rand(Complex => Int) isa Complex{Int}
572572
@test rand(Pair => (String, Int8)) isa Pair{String,Int8}
573-
@test_throws ArgumentError rand(1=>2) # should not call rand(make(1, 2))
573+
@test_throws MethodError rand(1=>2) # calls rand(make(1, 2))
574574

575575
@test rand(Complex => Int, 3) isa Vector{Complex{Int}}
576576
@test rand(Pair => (String, Int8), Set, 3) isa Set{Pair{String,Int8}}

0 commit comments

Comments
 (0)